html页面引入vue.js,vue,axios.min.js,使用this.$http.get(url, [options])
这种请求方式报错:Uncaught (in promise) TypeError: Cannot read properties of undefined (get),
解决方法,在new Vue上方添加如下代码:
Vue.prototype.$http = axios
<script>
Vue.prototype.$http = axios
// 该vue对象,绑定了页面中id是app的那个div
new Vue(
{
el: '#app', //element
// 数据哪里来?
data: {
title: 'hello nikey', //以后,数据是通过发送ajax请求,来获得的
tableData: []
},
created() {
this.send()
},
beforeCreate(){
},
mounted() {
},
methods: {
async send(){
const { data: res} = await this.$http.get('http://localhost:8090/ware/index/list')
console.log(res)
this.tableData = res.page.data;
}
}
</script>