How to interact with vue and the backend: 1. Use the [$http.get()] method to realize interaction; 2. Use the [$http.post()] method to realize interaction; 3. Use [$http .jsonp()] method to achieve interaction.
Vue.js (pronounced /vjuː/, similar to view) is a progressive framework for building data-driven web interfaces. The goal of Vue.js is to enable responsive data binding and composed view components with the simplest possible API. Not only is it easy to get started, it is also easy to integrate with third-party libraries or existing projects.
How to realize the front-end and back-end interaction of vue.js?
1. Use the $http.get() method
to obtain an ordinary text data
this.$http.get('a.txt').then(function(res){ alert(res.data); },function(res){ alert(res.status); });
Send data to the server (this You need to pass the second parameter {a:1, b:2} to the get method, which is the data to be sent)
this.$http.get('a.php', { a: 1, b: 2 }).then(function(res) { alert(res.data); }, function(res) { alert(res.status); });
2. Use the $http.post() method
At this time, you need to pass the third parameter {emulateJSON: true} to the post method
this.$http.post('a.php', { a: 1, b: 2 }, { emulateJSON: true }).then(function(res) { alert(res.data); }, function(res) { alert(res.status); });
3. Use the $http.jsonp() method
Visit 360 search interface
this.$http.jsonp('https://sug.so.360.cn/suggest', { params: { word: 'a' } }).then(function(res) { alert(res.data.s); }, function(res) { alert(res.status); });
Visit baidu search interface
this.$http.jsonp('https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su', { params: { wd: 'a' }, jsonp: 'cb' }).then(function(res) { alert(res.data.s); }, function(res) { alert(res.status); });
The above is the detailed content of How vue interacts with the backend. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
