Home >Web Front-end >Vue.js >How to install vue-resource

How to install vue-resource

青灯夜游
青灯夜游Original
2021-10-27 17:36:423479browse

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.

How to install 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn