Home > Article > Web Front-end > How to install vue-resource
Installation method: 1. Open the cmd command window and execute the "cd project directory" and "npm i vue vue-resource --save-dev" commands; 2. Configure the entry file "main.js" and use The import command can import vue-resource.
The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer.
vue-resource is a plug-in used in vue to request network data. This plug-in depends on vue. Simply put, it is used to adjust the interface.
Installation
cd 项目目录 npm i vue vue-resource --save-dev
Configure in the entry file main.js
import VueResource from 'vue-resource'Vue.use(VueResource)
That’s it Used directly:
get request:
this.$http.get('地址',{params: {参数}}).then(function(res) { console.log(res) // 响应成功回调 },function(res) { console.log(res) // 响应错误回调 })
post request:
this.$http.post('地址',{参数},{emulateJSON:true}).then( function(res) { console.log(res.data) })
jsonp request:
this.$http.jsonp("地址",{params:{参数}}).then( function(res){ console.log(res.data.s) })
Related recommendations: " vue.js tutorial》
The above is the detailed content of How to install vue-resource. For more information, please follow other related articles on the PHP Chinese website!