在 vscode vue中使用 axios和 element-ui
下载 axios
npm install axios -g
下载element-ui
npm i element-ui -S
Axios 全局引入
在main.js中使用
import axios from 'axios'
Vue.prototype.$axios=axios; //加载到原型上
就可以在script里直接使用了
如:
this.$axios.get('/...',{params:{id:123}}) 参数名在url内部 http://localhost:8088/getId?id=123的形式
.then((res)=>{console.log(res)
})
.catch((err)=>{
console.log(err)});
如:
this.$axios.post('/...',{ 参数名是某种类型 http://localhost:8088/getUser user的形式
id:'12',
username:'ddd'})
.then((res)=>{
console.log(res)})
.catch((err)=>{
console.log(err)});
Element-ui的引入
在main.js中引入,全局可用
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)

浙公网安备 33010602011771号