Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the function of emulateJSON in vue-resource

Shulou Source: shulou.com Published: 2022-06-02 09:24:46 10月25日 Update

This article will explain in detail what is the role of emulateJSON in vue-resource. The content of the article is of high quality, so Xiaobian shares it with you as a reference. I hope you have a certain understanding of relevant knowledge after reading this article.

import Vue from 'vue'

import App from './ App'

import router from './ router'

import VueResource from 'vue-resource'

Vue.use(VueResource);

Vue.config.productionTip = false

new Vue({

el: '#app',

router,

created(){

this.$ http.post('https://cnodejs.org/api/v1/topics',{

a:100,

b:'100'

}).then((data)=>{

console.log(data)

})

},

render: h => h(App)

})

The results are as follows:

If emulateJSON is set to true, vue-resource sends data as a post and sends it as a form, which is in this format: application/x-www-form-urlencoded.

To set emulateJSON to true (default false), simply add the following code to the main file:

Vue.http.options.emulateJSON=true

The test results are as follows:

You can see that after setting the emulateJSON property to true, the Content-Type in the request header changes to application/x-www-form-urlencoded, and the data transfer format changes to From Data format.

About the role of emulateJSON in vue-resource is what to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Tags: Format function content data article more knowledge article result yes that is code just need attribute form file way form quality as shown in the figure Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL NVidia Apple Shulou Information Redmi