Home > Web Front-end > Vue.js > body text

How to install vue-resource

青灯夜游
Release: 2021-10-27 17:36:42
Original
3459 people have browsed it

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
Copy after login

Configure in the entry file main.js

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

That’s it Used directly:

get request:

this.$http.get('地址',{params: {参数}}).then(function(res) {
        console.log(res)        // 响应成功回调
    },function(res) {
        console.log(res)        // 响应错误回调
    })
Copy after login

post request:

this.$http.post('地址',{参数},{emulateJSON:true}).then( function(res) {
      console.log(res.data)
    })
Copy after login

jsonp request:

this.$http.jsonp("地址",{params:{参数}}).then( function(res){
      console.log(res.data.s)
    })
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template