Vue中的前后台交互

先安装axiosnpm install axios然后在vue页面中进行编码:import axios from axios;export default {name: App,components: {},data: function(){return {my_pics: []}},methods: {getPicList(pic_dir) {const ...

先安装axios

npm install axios

然后在vue页面中进行编码:

import axios from 'axios';
	export default {
		name: 'App',
		components: {
		},
		data: function(){
			return {
				my_pics: []
			}
		},
		methods: {
			getPicList(pic_dir) {
				const path = 'http://127.0.0.1:5000/folder/'+pic_dir;
				axios.get(path, null, { params: {root:pic_dir}})
				.then((res) => {
					this.my_pics = res.data;
				})
				.catch((error) => {
					// eslint-disable-next-line
					console.error(error);
				});
			}
		},
		created() {
		},
	}

本文标题为:Vue中的前后台交互

基础教程推荐