[英]Vue.js conditionals
我有一个由别人用 vue.js 编写的前端项目。 当组件加载时存在多个链接时,我需要添加一个条件来显示链接。 如果我的某些术语不正确,我深表歉意,我之前没有使用过 vue.js 或任何类似的东西,而且我对 JavaScript 的了解有限。
这是我到目前为止所尝试的。 我迷路的是如何在页面加载时触发它。
var ConceptListItem = {
props: ['concept'],
template: `<div class="list-group-item concept-item clearfix" id="concept-{{ concept.uri }}">
<div id="conceptDiv">
<a v-if="ident" v-on:click="select" style="cursor: pointer;">{{ concept.label }} ({{ concept.authority.name }}) {{ concept.identities[0].concepts[0] }}</a>
<a v-else v-on:click="select" style="cursor: pointer;">{{ concept.label }} ({{ concept.authority.name }})</a>
</div>
<div class="text text-muted">{{ concept.description }}</div>
</div>`,
data: function() {
return {
ident: false,
}
},
methods: {
select: function() {
this.$emit('selectconcept', this.concept);
},
}
}
然后我尝试添加一个函数来在 vue 模板中创建
created () {
window.addEventListener('scroll', this.handleScroll);
window.addEventListener('resize', this.handleScroll);
var self = this;
document.getElementById('graphContainer').onmouseup = function() {
self.updateSwimRef();
self.handleScroll();
},
document.getElementById('conceptDiv')il. = function() {
self.ident = true;
}
},
让我们将所有链接保存到一个数组中,比如链接 [],在您的 html 中添加以下代码
<div v-if="links.length>1">
// your code with condition
</div>
<div v-else>
// else part if any
</div>
在 vue 部分,您需要通过以下方式添加数组,
data: function () {
return {
links: [],
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.