123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <template>
- <div class="q-pa-md position-relative">
- <q-input v-model="query" color="white" placeholder="Search ..." />
- <q-list class="search-results">
- <q-item clickable v-for="result in results" :key="result.item.title" @click="goTo(result.item.url)">
- <q-item-section>
- <q-item-label>{{ result.item.title }}</q-item-label>
- </q-item-section>
- </q-item>
- </q-list>
- </div>
- </template>
- <style>
- .position-relative {
- position: relative;
- }
- .search-results {
- position: absolute;
- color: white;
- width: 100%;
- background: rgba(166, 222, 214, 0.519);
- z-index: 9999;
- max-height: 200px;
- overflow-y: auto;
- }
- </style>
- <script>
- export default {
- data() {
- return {
- query: "",
- results: [],
- documents: [
- {
- title: "Introduction",
- content: "This is the introduction to our documentation...",
- url: "/docs/introduction",
- },
- {
- title: "Getting Started",
- content: "Here's how to get started with our project...",
- url: "/docs/getting_started",
- },
- // More documents...
- ],
- fuse: null,
- };
- },
- watch: {
- query() {
- this.search();
- },
- },
- created() {
- let options = {
- keys: ["title", "content"],
- };
- this.fuse = new Fuse(this.documents, options);
- },
- methods: {
- search() {
- this.results = this.fuse.search(this.query);
- console.log(this.results);
- },
- goTo(url) {
- this.$router.push(url);
- },
- },
- };
- </script>
|