[英]how to pass an element from mounted to HTML template
I get some data from api in mounted. 我从已安装的api中获取了一些数据。 I'd like to pass them to html template by the loop, but it is still doesn't work.
我想通过循环将它们传递给html模板,但仍然无法正常工作。
HTML HTML
.date
.values(v-for="el in document")
span {{el.created}}
span {{el.document_title}}
.actions_value
.pic
i.fas.fa-download
span download
VUE.JS VUE.JS
export default {
data() {
return {
document: {}
};
},
mounted() {
co.getDocuments(
this.$store.getters.customer_id,
this.$store.getters.token
).then(data => {
let dataDoc = data.data;
console.log(dataDoc);
Object.values(dataDoc).map(document => {
return (this.document = document);
});
});
}
};
My el in the loop doesn't exist.I tried to assign a document to this.document. 我的循环中的el不存在。我尝试将文件分配给this.document。 But still somenthig is wrong.
但是somenthig仍然是错误的。
You cannot access the Vue component reference within the map function by using this keyword. 您无法使用此关键字访问map函数内的Vue组件引用。 So, I suggest you to bind the Vue component reference instead of the default this operator.
因此,我建议您绑定Vue组件引用,而不要绑定默认的this运算符。
Object.values(dataDoc).map(
function(document) {
this.document = document;
}.bind(this) **// like this**
);
sample: https://codesandbox.io/s/vue-template-3hmom 样本: https : //codesandbox.io/s/vue-template-3hmom
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.