vue学习第21天,vue-resource 插件

来源:互联网 发布:酷家乐软件好用吗 编辑:程序博客网 时间:2024/06/10 17:33

1,npm install vue-resource --save 安装插件 插件是上线后也要用的

2,一般都在 node_modules/vue-resource/dist/vue-resource.js 路径

3,构建一个 vue 实例 然后 使用 v-on:click="get"  v-on:click="post" 触发请求

4,get 请求 一般传两个参数 this.$http.get("目标文件",{配置属性})

 配置属性包括 params:{userid:id}这个是必须的 

还可以往请求头塞东西 headers:{token:'abcd'}

get(...).then(成功的回掉,失败的回掉) 

成功的回掉 res=>{this.msg=res.data}

 失败的回掉 error=>{this.msg=error}

5,post 请求 传三个参数 this.$http.post("目标文件",参数,属性配置)

参数是要提交的数据

属性配置里面可以往请求头里面塞东西 headers:{post-token:'token'}

post(...).then(成功的回掉,失败的回掉) 

成功的回掉 res=>{this.msg=res.data}

失败的回掉 error=>{this.msg=error}


原创粉丝点击