{{item.name}}
{{formatCount(item.playCount)}}
以上是组件的代码,确定axios已经正确安装,调用的localhost:3000接口api程序也在本地正常运行,经测试可以正常返回数据,但是无法到页面上就无法显示数据,chrome控制台报错
所以到底是哪里出了问题,请大神解答
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
export default {} 前面加 import axios from 'axios'试试
个人是在mian.js中这么写
`import axios from 'axios';
Vue.prototype.$http = axios;`
调用
this.axios是 undefined。说明你引入的axios没有绑到 Vue 上。试下在 app 入口的地方,给 Vue 的原型加上。
大概类似这样:
或者自己参考下怎么给Vue写插件: https://vuejs.org/v2/guide/pl...
在 script 标签中最前面添加一行
import axios from 'axios'魔改原型链以及在 Vue 实例中的 this 绑东西添加都不是推荐的做法。
不需要this,直接Axios.get()