【发布时间】:2019-10-31 09:54:08
【问题描述】:
我正在尝试创建一个 vue 应用程序。测试版is here。我正在处理的问题是 main.js 中的 vue 构造函数需要设置 Quote 对象的属性但不是。
Quote vue 文件有这个。
import card from './components/Card.vue'
import quoteheader from './components/QuoteHeader.vue'
export default{
data: function(){
return {
title: "",
quotecards: []
}
},
methods: {
addCard : function(obj){
this.quotecards.push(
{
id: this.quotecards.length + 1,
title: obj.title
}
);
//console.log(this.quotecards);
},
updateCriteria(tmp){
///console.log(tmp);
}
},
components: {
card, quoteheader
}
}
启动它的 main.js 有这个。
new Vue({
el: "#app",
render: h => h(Quote, {
props: {
title: "test",
quotecards: [
{ id: 0, title: "title 1"},
{ id: 1, title: "title 2"}
]
}
})
})
当应用程序启动时,我希望quotecards 数据应该是一个包含 2 个项目的数组,并且quote vue 文件的模板字段中的文本字段应该具有“test”的值。相反,quotecards 长度为 0,输入为空。
【问题讨论】:
-
请更新您的问题以包含您认为相关的代码部分,而不是依赖外部链接。
-
问题已更新。
标签: vuejs2 vue-component