【发布时间】:2018-04-23 07:42:04
【问题描述】:
我在 VueJS 上有一个错误,在 Axios 响应的 v-for 中添加了一个过滤器,我不知道如何解决它。如果我在 value 变量上创建了 console.log,过滤器 set_marked 将返回一个 undefined 值。
这是 HTML:
<main id="app">
<div v-for="item in productList" :key="item.id">
<header>
<h2>{{ item.title }}</h2>
</header>
<article class="product-card">
{{ item.content | set_marked }}
</article>
</div>
</main>
还有 Javascript:
var app = new Vue({
el: '#app',
data: {
loading: false,
loaded: false,
productList: []
},
created: function() {
this.loading = true;
this.getPostsViaREST();
},
filters: {
set_marked: function(value) {
return marked(value);
}
},
methods: {
getPostsViaREST: function() {
axios.get("https://cdn.contentful.com/spaces/itrxz5hv6y21/environments/master/entries/1Lv0RTu6v60uwu0w2g2ggM?access_token=a2db6d0bc4221793fc97ff393e541f39db5a65002beef0061adc607ae959abde")
.then(response => {
this.productList = response.data;
});
}
}
})
你也可以在我的 codepen 上试试: https://codepen.io/bhenbe/pen/deYRpg/
感谢您的帮助!
【问题讨论】:
-
什么是
marked函数? -
这是我添加的另一个库以显示降价内容:github.com/markedjs/marked
-
那么为什么不将它包含在演示中呢?
-
这似乎不是问题。我的错误发生在标记的函数调用之前。
标签: javascript vuejs2 axios