vscode 搭建vue项目 使用axios(ajax)

安装

cnpm install --save axion vue--axion

main.js中引入axios

import axios from 'axios';

import VueAxios from 'vue-axios';

Vue.use(VueAxios,axios);

项目使用:

<template>
  <div id="app">
    <div style="width:50%" class="container">
      <div>
        <h3>注册</h3>

<br/>
        <h4>邮箱</h4>
          <input type="text" class="form-control" v-model.trim="mail"/><br/>
          {{mail}}
        <h5>密码</h5>
          <input type="password" class="form-control" v-model="password"/><br/>
          {{password}}
        <input class="btn btn-info" type="submit" value="注册" @click="submitBtn">
      </div>
    </div>
  </div>
</template>




<script>
export default {
  name: 'App',
  data(){
    return {
      mail: "",
      password: "",
      hobby: ""
    }
  },
  methods:{
    submitBtn:function () {
      this
        .axios({
          method: "post",
          url: "http://127.0.0.1:3001/admin-center/adminUser/regist",
          data: {
            mail: this.mail,
            password: this.password
          }
        })
        .then(function (response){
          console.log(response.log)
          alert(response.data)
        })
        .catch(function (response){
          console.log(response.message)
          alert(response)
        })
    }
  }
}
</script>



<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
发布了134 篇原创文章 · 获赞 26 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/inflaRunAs/article/details/105461541
今日推荐