本文主要參考了Vue2.0 新手完全填坑攻略—從環境搭建到發佈——Jinkey 原創。跟其主要區別在於本文使用了element ui和其提供的element starter,同時本文不涉及vue-resource。之前的構建過程見一個初學者的vue2.0練習程序。源碼可以在github看到。
- 首先在main.js中引入vue-resource
import VueResource from 'vue-resource'
...
Vue.use(VueResource)
在secondCom.vue中使用vue-resource
<script> export default { data() { return { ... } }, mounted: function() { this.$http.jsonp('https://api.douban.com/v2/movie/top250?count=10', {}, { headers: { }, emulateJSON: true }).then(function(response) { // 這裏是處理正確的回調 this.articles = response.data.subjects }, function(response) { // 這裏是處理錯誤的回調 console.log(response) }); } } </script>