本帖最后由 ing 于 2019-9-30 21:22 编辑
写在methods下的 this.docState 访问不到 data 下的数据 docState ,但标签v-for可以遍历出来
this.docState 的值是undefined
完整[Asm] 纯文本查看 复制代码 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app"></div>
<script src="https://unpkg.com/vue"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/velocity/1.2.3/velocity.min.js"></script>
<div id="todo-list-example">
<transition v-for="s in docState">
<button v-bind:key="s.state" @click="buttonMessage">
<slot>{{s.state}}</slot>
</button>
</transition>
</div>
<script type="text/javascript">
var vm = new Vue({
el: '#todo-list-example',
data: {
docState: [{
state: 'saved'
},
{
state: 'edited'
},
{
state: 'editing'
}
]
},
methods: {
buttonMessage: function() {
switch (this.docState) {
case 'saved':
return 'Edit'
case 'edited':
return 'Save'
case 'editing':
return 'Cancel'
}
}
}
})
</script>
</html> |