25 vue之axios

1 安装

cnpm install axios -S

25 vue之axios

 

 

2 使用

Home.vue

<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png">

    <button @click="handleClick">点我获取数据</button>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  name: 'Home',
  methods:{
    handleClick(){
        axios.get('http://127.0.0.1:5000/').then(res=>{
            console.log(res)
            console.log(res.data)
        }).catch(error=>{
            console.log(error)
        })
    }
  }

}
</script>

25 vue之axios

backend.py

# -*- coding: utf-8 -*-
# @Time    : 2021/12/28 20:35
# @Author  : dzg
from flask import Flask, jsonify, make_response, request
from flask_cors import CORS

app = Flask(__name__)

CORS(app, resource='/*')


@app.route('/', methods=['GET'])
def index():
    return '我是后端传过来的数据'


if __name__ == '__main__':
    app.run()

25 vue之axios

 

上一篇:1130 Infix Expression (25 分)


下一篇:力扣每日一题2021-12-25中等题:奇偶树