The content of this article is about how to introduce the vue-resource module in vue.js and implement http cross-domain requests. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. help.
Reference the vue-resource module in the vue project
npm install vue-resource --save-dev
Reference in the main.js file
//引入 vue-resource模板 import VueResource from 'vue-resource' Vue.config.productionTip = false; Vue.use(VueResource); new Vue({ el: '#app_head', components: { App_head }, template: '<App_head/>', created(){ //created() 网页运行时触发 this.$http.get("http://jsonplaceholder.typicode.com/users") //使用http请求 .then((data) =>{ //请求成功后返回结果给 data console.log(data); }) } });
There may be cross-domain request issues
You can add this code to the php file
<?php header("Access-Control-Allow-Origin: *"); ?>
Related recommendations:
Detailed explanation of how Vue-cli implements cross-domain requests
Introduction to the configuration method of router in vue.js
The above is the detailed content of How to introduce the vue-resource module in vue.js and implement http cross-domain requests. For more information, please follow other related articles on the PHP Chinese website!