我正在尝试将主Vue实例中的prop传递给组件。我正在传递两个道具,第一个有效,但第二个不出于某种原因。
var app7 = new Vue({
el: '#app-7',
template: `<div class="b">
<div>
<button class="c" v-on:click="previousDay">‹</button>
<h1 >{{ this.ss }}</h1>
<button class="c" v-on:click="nextDay">›</button>
<div>
<emp-item
v-for="item in empList"
v-bind:emp="item"
v-bind:key="item.id">
v-bind:lines="lines"
</emps-item>
</div>`,
data: function() {
return {
empList : l,
lines: 0,
day: 0
}
// other stuff
Vue.component('emp-item', {
props: ['emp', 'lines'],
template: `<div class="cv">
<h6>{{emp.first_name}} {{ lines }}</h6>
<canvas v-on:mousedown="mouseDown" v-on:mousemove="mouseMove" v-on:mouseup="mouseUp" :id="'cv' + emp.id" class="canvas" width="150" height="700"></canvas>
</div>`,
data: function() {
return {
rect : {},
drag : false,
startTime : 0,
cv: ''
}
},
watch: {
lines: function () {
console.log('watch: ');
}
},
// methods
<div id="app-7">
<app></app>
</div>
答案 0 :(得分:1)
在绑定第二个道具之前关闭组件标记。它应该是这样的:
var app7 = new Vue({
el: '#app-7',
template: `<div class="b">
<div>
<button class="c" v-on:click="previousDay">‹</button>
<h1 >{{ this.ss }}</h1>
<button class="c" v-on:click="nextDay">›</button>
<div>
<emp-item
v-for="item in empList"
v-bind:emp="item"
v-bind:key="item.id"
v-bind:lines="lines">
</emps-item>
</div>`,
data: function() {
return {
empList : l,
lines: 0,
day: 0
}
})