vue不能set数据
粉丝福利 : 关注VUE中文社区公众号,回复视频领取粉丝福利
- demo环境:版本VUE2,html和test.json在同一个目录下
- 为甚不能set数据?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>click</title>
</head>
<body>
<div id="app">
{{gridData}}{{apiUrl}}
</div>
</body>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="http://cdn.bootcss.com/vue-resource/1.0.2/vue-resource.common.js"></script>
<script>
var demo = new Vue({
el: '#app',
data: {
gridData: "",
apiUrl: 'test.json'
},
created: function() {
this.getCustomers()
},
methods: {
getCustomers: function() {
this.$http.get(this.apiUrl)
.then((response) => {
console.log(response.success)
this.$set('gridData', response.success)
})
.catch(function(response) {
console.log(response)
})
}
}
})
</script>
</html>
test.json 就这样一个字段{success:1}
刚刚开始学VUE,请大家的多多指教