当前位置:首页 > js > vue

Uncaught TypeError: this.$http is undefined

2023-05-09 来源:无名网 作者:无名网整理

Vue与后端数据交互问题

使用this.$http.get('请求地址')来发送请求。浏览器报错:Uncaught TypeError: this.$http is undefined

解决

需要引入库:vue-resource

<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>

vue2.0版本的推荐使用axios

使用 cdn:

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

<script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>

使用 npm:

$ npm install axios

使用 bower:

$ bower install axios

使用 yarn:

$ yarn add axios
相关内容:
『 猜你喜欢 』