1、執(zhí)行命令:
npm install vue-jsonp --save
2蜡感、src/main.js中添加:
import VueJsonp from 'vue-jsonp'
Vue.use(VueJsonp)
3争占、其它組件中基本使用方法:
this.$jsonp(rootApi+'/company/Info'',傳參參數(shù)對(duì)象{}).then(json => {
????????// 返回?cái)?shù)據(jù) json, 返回的數(shù)據(jù)就是json格式
}).catch(err => {
console.log(err)
})
4谈撒、其他實(shí)例:
4.1:
this.$jsonp(ApiRoot+'/company/Info',
{
????callbackQuery: 'callbackParam',// jsonp key //請(qǐng)求傳遞參數(shù)1
????callbackName: 'jsonpCallback',// jsonp key //請(qǐng)求傳遞參數(shù)2
????name: 'zhangsan',//請(qǐng)求傳遞參數(shù)3type: 6//請(qǐng)求傳遞參數(shù)4
}).then(json => {
????//返回?cái)?shù)據(jù)json,返回的數(shù)據(jù)就是json格式
}).catch(err => {
????console.log(err)
})
4.2:
this.$jsonp(ApiRoot+'/company/Info',
????Object.assign(
????????this.$store.state.common, ????
????????{? ?
????????????callbackQuery: 'callbackParam',
????????????callbackName: ????'jsonpCallback'
????????}
????)
).then(json => {
? ? _this.pageData = json.result
}).catch(err => {
????console.log(err)
})
----
說明:Object.assign() 為 es6 javascript對(duì)象方法匾南,功能是合并多個(gè)對(duì)象數(shù)據(jù)
(轉(zhuǎn)載請(qǐng)注明出處啃匿,首次發(fā)表于 http://www.cnblogs.com/rapale/p/7839203.html )