1、首先在安装axios,npm install axios --save
2、然后在main.js里面引入
import axios from 'axios'
Vue.prototype.$axios = axios(也可以写Vue.prototype.$http=axios)
3、最后在页面上的应用
在data(){
return{
muensList :{}
}
}
在methods里面
created() {
this.$axios.get('./static/data.json') // 存放json的路径
.then((res) => {
this.muensList = res
console.log(this.muensList)
})
.catch((error) => {
alert(error)
})
}