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

How to install vue-resource

Oct 27, 2021 pm 05:36 PM
vue 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.

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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use echarts in vue How to use echarts in vue May 09, 2024 pm 04:24 PM

How to use echarts in vue

The role of export default in vue The role of export default in vue May 09, 2024 pm 06:48 PM

The role of export default in vue

How to use map function in vue How to use map function in vue May 09, 2024 pm 06:54 PM

How to use map function in vue

The difference between event and $event in vue The difference between event and $event in vue May 08, 2024 pm 04:42 PM

The difference between event and $event in vue

The difference between export and export default in vue The difference between export and export default in vue May 08, 2024 pm 05:27 PM

The difference between export and export default in vue

The role of onmounted in vue The role of onmounted in vue May 09, 2024 pm 02:51 PM

The role of onmounted in vue

What scenarios can event modifiers in vue be used for? What scenarios can event modifiers in vue be used for? May 09, 2024 pm 02:33 PM

What scenarios can event modifiers in vue be used for?

What are hooks in vue What are hooks in vue May 09, 2024 pm 06:33 PM

What are hooks in vue

See all articles