vue不能set数据
发布于 7 年前 作者 liuestc 7276 次浏览 来自 问答
粉丝福利 : 关注VUE中文社区公众号,回复视频领取粉丝福利
  1. demo环境:版本VUE2,html和test.json在同一个目录下
  2. 为甚不能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,请大家的多多指教

回到顶部