vueでインタフェースを要求する2つの方法
vueプロジェクトインストールaxios:
インストールqs:
main.js内容:
必要なページリクエストインタフェースのgetとpostの2つの方法:
cnpm install axios --save
import axios from 'axios'
インストールqs:
npm install --save axios vue-axios qs
import qs from 'qs' qs vue post a=a&b=b
main.js内容:
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import axios from 'axios' ( )
import qs from 'qs' ( )
import 'element-ui/lib/theme-chalk/index.css'
import '@/assets/styles/common.scss'
import moment from 'moment'
import Highcharts from 'highcharts'
import echarts from 'echarts'
Vue.use(ElementUI)
Vue.prototype.Highcharts=Highcharts
Vue.prototype.echarts=echarts
Vue.prototype.$ajax=axios ( )
Vue.prototype.$qs=qs ( )
Vue.use(Highcharts)
Vue.use(echarts)
Vue.config.productionTip = false
Vue.prototype.$moment=moment
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
store,
components: { App },
template: ''
})
必要なページリクエストインタフェースのgetとpostの2つの方法:
loadData(){
//get
var _this=this;
_this.$ajax.get(`../static/tsconfig.json`)
.then(res=> {
let data=res.data.data;
console.log(data.description)
})
.catch(error=>{
console.log(error)
})
},
loadPost(){
//post
var _this=this;
_this.$ajax.post(
`../static/tsconfig.json`,
_this.$qs.stringify({
sname:'hahaha'
})
)
.then(res=> {
let data=res.data.data;
console.log(data.description)
})
.catch(error=>{
console.log(error)
})
},