vue-resource和vue-async-data两个插件的使用,看了一下文档
var Vue = require("vue"), App = require("./App.vue");var vueResource = require('vue-resource');Vue.use(vueResource);var vm = new Vue({ el: 'body', ready: function(){ this.$http.get('./src/test.json', {}, { headers: { "X-Requested-With": "XMLHttpRequest" }, emulateJSON: true }).then(function(response) { var data = response.data; this.msg = data; }, function(response) { // handle error }); }, data: { msg: "hello", dom: "body" }});
简单来说, vue-resource就像jQuery里的$.ajax, 用来和后端交互数据的...你可以放在created或者ready里面运行来获取或者更新数据...
vue-async-data应该是封装了下更新数据的方法, 不过还是需要vue-resource去做交互
var Vue = require("vue"), App = require("./App.vue");var vueResource = require('vue-resource');var VueAsyncData = require('vue-async-data')Vue.use(vueResource);Vue.use(VueAsyncData);var vm = new Vue({ el: 'body', asyncData: function (resolve, reject) { this.$http.get('./src/test.json', {}, { headers: { "X-Requested-With": "XMLHttpRequest" }, emulateJSON: true }).then(function(response) { var data = response.data; resolve({ msg: data }); }, function(response) { // handle error }); }, data: { msg: "hello", dom: "body" }});