//main.js
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
Vue.config.productionTip = false;
Vue.prototype.$ajax = axios;
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})
//HelloWorld重写文件
<script>
import '../mock/mock'
export default {
name: 'HelloWorld',
data () {
return {
msg:'hello world',
data:[]
}
},
mounted:function () {
console.log(111);
this.getList()
},
methods:{
getList(){
this.$axios.get('/api/data').then((res)=>{
console.log(res);
})
}
}
}
</script>
//mock.js文件
import Mock from 'mockjs'
//使用mockjs模拟数据
Mock.mock('/api/data', (req, res) => {
return {
data: ['a','b']
}
})
不论怎么该一致报错未定义~求教下到底哪里没配置好?
参考的这篇文章https://segmentfault.com/a/11...
又翻了很多文章,终于找到了问题所在,
调用的地方
改为