vue-resource的使用

作者: 简小咖 | 来源:发表于2017-10-06 10:59 被阅读16次

vue-resource是Vue的插件,用来与远程服务器端通信,相当于ajax

在项目中安装

npm install vue-resource --save

引入

在main.js中

import  VueResource  from 'vue-resource'
Vue.use(VueResource) 

使用

<script>
export default {
  name: 'hello',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App'
    } 
  },
  created:function (){
        this.$http.get('/api/cakeList/').then((response) => {
        console.log(response.data);
      })
    }
}
</script>

运行的时候,要启动Apache

相关文章

网友评论

    本文标题:vue-resource的使用

    本文链接:https://www.haomeiwen.com/subject/typlyxtx.html