最朴素的vue3代码了

<!DOCTYPE html>
<html>
<head>
  <title>Your Vue 3 App</title>
  <!-- 引入 Vue 3 的 CDN 文件 -->
  <script src="https://unpkg.com/vue@3.2.26/dist/vue.global.js"></script>
  <!-- 引入 axios 的 CDN 文件 -->
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<!-- Vue 3 应用的根元素 -->
<div id="app">
  <!-- 表单 -->
  <form @submit.prevent="submitForm">
    <!-- 输入用户名 -->
    <label for="username">用户名:</label>
    <input type="text" id="username" v-model="username" />

    <!-- 输入密码 -->
    <label for="password">密码:</label>
    <input type="password" id="password" v-model="password" />

    <!-- 提交按钮 -->
    <button type="button" @click="submitForm">登录</button>
  </form>
</div>

<script>
  // 创建 Vue 3 应用
  const app = Vue.createApp({
    data() {
      return {
        username: '',
        password: ''
      };
    },
    methods: {
      submitForm() {
        // 构造请求参数
        const data = {
          username: this.username,
          password: this.password
        };

        // 创建带有基本URL的 Axios 实例
        const api = axios.create({
          baseURL: 'http://127.0.0.1:18885' // 你的后端API的基本URL
        });

        // 发起 POST 请求
        api.post('/huarun/test',data)
        .then(response => {
          // 请求成功处理
          console.log(response.data);
        })
        .catch(error => {
          // 请求失败处理
          console.error(error);
        });

        // 发起 GET 请求
        // api.get('/huarun/test',{
        //   params: {
        //     username: this.username,
        //     password: this.password
        //   }
        // })
        // .then(response => {
        //   // 请求成功处理
        //   console.log(response.data);
        // })
        // .catch(error => {
        //   // 请求失败处理
        //   console.error(error);
        // });

        
      }
    }
  });

  // 挂载 Vue 3 应用到根元素
  app.mount('#app');
</script>
</body>
</html>

最朴素的vue3代码了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值