vue.js加载json数据

在使用jQuery的情况下

$(function() {
	$.ajax({
		type: 'get',
		url: 'data.json',
		success: function(data) {
			if (data.msg == "ok") {
				pushDom(data.data);
			} else {
				alert("服务器返回异常");
			}
		},
		error: function(data) {
			alert(JSON.stringify(data));
		}
	});

	function pushDom(data) {

		var vue = new Vue({
			el: '#app',
			data: {
				vue: data
			},
			computed: {

			},
			methods: {

			}

		});
	}

});




操作数组显示方法:

data:{
    vue1:data.data1,
    vue2:data.data2
}


使用axios加载

new Vue({
  el: '#app',
  data (){
	  return{
        data:[]
	  }
  },

        created() {
            axios.get('data.json').then(response => 
            {
                 this.data = response.data.data;
                 //这里打印结果
                 console.log(JSON.parse(JSON.stringify(response.data))['data']);
            });
          }
})

猜你喜欢

转载自blog.csdn.net/weixin_40431771/article/details/83415158