1. Introduction Recently, I encountered a cross-domain problem when working on a handwriting input method. I used the interface of the QQ input method, and the proxy could not achieve the effect. Here I used jsonp to implement it. You can search Baidu for the principle of jsonp yourself. Here I will record the use of 2. Installationnpm install vue-jsonp -S or yarn add vue-jsonp 3. Usemian.js reference // main.js import Vue from 'vue' import { VueJsonp } from 'vue-jsonp' Vue.use(VueJsonp) // $jsonp is mounted on the vue prototype and can be used directly with vm.$jsonp()
4. Use of vue filesthis.$jsonp('/some-jsonp-url', { myCustomUrlParam: 'veryNice' }).then(res => { // The code here is not executed // because the returned callback function will be called directly}) Assuming the name of the returned function is callbackFun, you need to bind the callbackFun function to the window object. mounted() { // Bind the callbackFun method to the window object window['callbackFun'] = (data) => { cosole.log('defined callback function') } // Assume that callbackFun.ajax_callback() is returned window['callbackFun'] = { ajax_callback: function (res) { cosole.log('defined callback function') } } }
This is the end of this article about how to use jsonp in vue. For more information about the use of jsonp in vue, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Analyze the compilation and burning of Linux kernel and device tree
>>: Example code for implementing transparent gradient effects with CSS
Table of contents Preface Modifiers of v-model: l...
Background: Some experiments need to be completed...
Table of contents 1. Directive custom directive 2...
I recently watched Apple's press conference a...
<br />This tag can be used to directly add a...
1. Install nginx in docker: It is very simple to ...
Online shopping mall database-user information da...
Table of contents 1. Environment variable $PATH: ...
Reinventing the wheel, here we use repackaging to...
The nginx configuration file is mainly divided in...
Detailed explanation of HTML (select option) in ja...
Comprehensive understanding of html.css overflow ...
Due to the default bridge network, the IP address...
1. What is semanticization? Explanation of Bing D...
Table of contents 1. Introduction 2. Back up the ...