pau*_*uvo 3 javascript vue.js vuejs2
我有代码(vuejs2)-
Vue.component('competetion-list', {
template: `<div>{{totalCompetetions}}</div>`,
props: ['values'],
data: function () {
return { totalCompetetions: this.values.length}
}
})
Run Code Online (Sandbox Code Playgroud)
页面上没有打印任何内容,但是如果我将template值更改为
template: `<div>{{this.values.length}}</div>`
Run Code Online (Sandbox Code Playgroud)
它打印15。我在做错什么,如何将其传递props给data?
任何帮助深表感谢。
我无法通过以下方式将道具分配values给数据totalCompetetions-
data: function () {
return { totalCompetetions: this.values.length}
}
Run Code Online (Sandbox Code Playgroud)
watch,computed和methods性能。
随着watch物业-
watch: {
values: function(){
this.totalCompetitions = this.values;
}
}
Run Code Online (Sandbox Code Playgroud)
随着computed物业-
computed:{
competition:{
get: function(){
return this.values.length;
}
}
Run Code Online (Sandbox Code Playgroud)
随着methods物业-
methods:{
competitionn: function(){
return this.values.length;
}
}
Run Code Online (Sandbox Code Playgroud)
computed和methods属性,我需要以totalCompetetions以下方式进行设置-
对于computed-
template: `<div><p>{{totalCompetitions = competition}}</p></div>` //without parenthesis
Run Code Online (Sandbox Code Playgroud)
对于methods-
template: `<div><p>{{totalCompetitions = competition()}}</p></div>` //with parenthesis
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6766 次 |
| 最近记录: |