【发布时间】:2023-03-31 18:43:01
【问题描述】:
这里我的搜索工作正常,但我是新手,不知道如何使用 npm...我正在使用带有 VueJS 的 HTML 来实现这一点,并成功创建了搜索过滤器,但无法实现高亮过滤器。 .一些线索是使用的markjs.io和其他一些自定义vuejs过滤器,但无法实现它们。
class Post {
constructor(title, link, author, img, course, coursel, cours, coursl, cour, courl, cou, coul, co, col) {
this.title = title;
this.link = link;
this.author = author;
this.img = img;
this.course = course;
this.coursel = coursel;
this.cours = cours;
this.coursl = coursl;
this.cour = cour;
this.courl = courl;
this.cou = cou;
this.coul = coul;
this.co = co;
this.col = col;
}
}
const app = new Vue({
el: "#app",
data: {
search: "",
postList: [
new Post("abc", null, "xyz", "wqw", "qwe", "", " ", null, " ", null, " ", null, " ", null, );
]
},
computed: {
filteredList() {
return this.postList.filter(post => {
return post.title.toLowerCase().includes(this.search.toLowerCase()) ||
post.author.toLowerCase().includes(this.search.toLowerCase()) ||
post.course.toLowerCase().includes(this.search.toLowerCase()) ||
post.cours.toLowerCase().includes(this.search.toLowerCase()) ||
post.cour.toLowerCase().includes(this.search.toLowerCase()) ||
post.cou.toLowerCase().includes(this.search.toLowerCase()) ||
post.co.toLowerCase().includes(this.search.toLowerCase());
});
}
}
});
这是我正在使用的 HTML 代码
<div id="app">
<div class="search-wrapper">
<input type="text" v-model="search" placeholder="Search"
onfocus="if(this.value==this.defaultValue)this.value=''"
onblur="if(this.value=='')this.value=this.defaultValue" />
</div>
<div class="wrapper">
<div class="col-lg-12 col-md-4 card" v-for="post in filteredList">
<a v-bind:href="post.link" target="_blank">
<img v-bind:src="post.img"/>
<div style="line-height:20%;">
<br>
</div>
<font size="2">{{ post.author }}</font>
<div class="brmedium"></div>
<font size="5"><b><i><em>{{ post.title }}</em></i></b></font>
<a v-bind:href="post.coursel" title="View Credential" target="_blank"><font size="3">{{ post.course }}</font></a>
<a v-bind:href="post.coursl" title="View Credential" target="_blank"><font size="3">{{ post.cours }}</font></a>
<a v-bind:href="post.courl" title="View Credential" target="_blank"><font size="3">{{ post.cour }}</font></a>
<a v-bind:href="post.coul" title="View Credential" target="_blank"><font size="3">{{ post.cou }}</font></a>
<a v-bind:href="post.col" title="View Credential" target="_blank"><font size="3">{{ post.co }}</font></a>
</a>
</div>
</div>
</div>
【问题讨论】:
-
这和 npm 有什么关系? npm 是一个包管理器。
-
我还不知道如何使用 npm 并将包添加到代码中..我的代码只有 HTML、CSS 和这个 JS 文件..
-
你的标题说你不想用npm,你的帖子讲了一些和npm无关的东西,所以:为什么要提到npm?
-
通常开发人员不使用 html 和 vuejs 并使用 jsx(也不确定)所以我不会在这方面吸引答案..
-
这仍然与 npm 无关,但也不是真的。很多人使用 vue,很多其他人使用 react,但是更多的人使用“这两者都不是”。只需用正确的标签标记您的问题,并在必要的程度上对问题进行标题和描述,让其他人帮助您。
标签: javascript html css vue.js vuejs2