Vue.js 搜索结果页面代码示例:Page.vue
<template>
<div>
<h1>Search Results</h1>
<ul>
<li v-for="result in searchResults" :key="result.id">
<h2>{{ result.title }}</h2>
<p>{{ result.description }}</p>
</li>
</ul>
</div>
</template>
<script>
export default {
data() {
return {
searchResults: []
};
},
mounted() {
// 在这里进行搜索结果的获取,可以通过调用API或其他相关操作
// 假设结果是一个数组,每个元素包含id、title和description属性
const searchQuery = 'example search query'; // 假设搜索查询是 'example search query'
// 调用API进行搜索并更新searchResults
this.searchResults = [
{ id: 1, title: 'Result 1', description: 'This is the first search result' },
{ id: 2, title: 'Result 2', description: 'This is the second search result' },
{ id: 3, title: 'Result 3', description: 'This is the third search result' }
];
}
};
</script>
<p>在上述代码示例中,Page.vue组件展示了一个标题为'Search Results'的页面,使用<code>v-for</code>指令迭代搜索结果数组<code>searchResults</code>并展示每个结果的标题和描述。在<code>mounted</code>钩子函数中,可以进行搜索的操作,这里简单地设定了一个搜索查询,并模拟调用API进行搜索,并将搜索结果更新到<code>searchResults</code>变量中。你可以根据实际情况进行调整和扩展。</p>
原文地址: https://www.cveoy.top/t/topic/qAo7 著作权归作者所有。请勿转载和采集!