Step1 示例代码如下
data() {
return {
list: [],
good: '222',
}
},
created() {
window.app = this
},
就是在created()里给程序起一个名字.
Step2 在控制台输入
app.good //显示222
Step1 示例代码如下
data() {
return {
list: [],
good: '222',
}
},
created() {
window.app = this
},
就是在created()里给程序起一个名字.
Step2 在控制台输入
app.good //显示222
Step1 安装axios. 在项目根目录运行如下指令
npm install axios --save
Step2 编辑/src/main.js, 在其中的合适位置加入如下代码
import axios from 'axios'
Vue.prototype.$axios = axios
并使其符合eslint格式
Step3 使用. 如在index.vue中的合适位置加入如下代码
mounted: function () {
this.$axios({
url: 'https://api.class4ever.com',
method: 'get',
params: {},
}).then((res) => {
console.log(res)
})
},
这样就可以访问API啦
component的template必须有一个根元素把它套住, 否则就会导致router-view不显示
例如, 如下是可以的
component: {
template: '<div>我是内容</div>'
}
而如下则不显示
component: {
template: '我是内容'
}