父组件变量传给子组件,子组件修改后回传给父组件,无法修改
<div id="app">
<navbar :list="nav" :current="current"></navbar>
</div>
<template id="navbar">
<div class="col" v-for="(item,index) in list" @click="setCurrent(index)">
<div :class="{current:current==index}">{{item.name}}</div>
</div>
</template>
<script>
new Vue({
el: '#app',
data: {
nav: [{
name: '标题',
type: 'title'
}, {
name: '颜色',
type: 'color'
}],
current: 0
},
methods: {
onCurrent: function(index) {
console.log(index);
this.current = index;
}
},
components: {
navbar: {
props: ['list', 'current'],
template: '#navbar',
methods: {
setCurrent: function(index) {
this.$emit('on-current', index);
}
}
}
}
});
</script>
子组件中setCurrent正常执行,父组件onCurrent却没有反应,而且父组件的current变量未发生变化;
有哪位大大帮看看什么情况
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…