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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),





