test.json和html在同一路径下,为甚不能设置初始数据?
<!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='js/vue-resource.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": true
}
看了下,把create去掉,运行初始数据是没有问题的。你看看程序有没有报错什么的,感觉是你created里面的函数有问题。改下路径试试