当前位置: 首页 > news >正文

表单提交是

首先,确保你已经安装了Vue 3、Element UI和axios(用于发送HTTP请求)。你可以使用以下命令进行安装:

 

bash复制代码

npm install vue@next element-ui axios --save

 


<template>  <el-form :model="form" :rules="rules" ref="form" label-width="120px">  <el-form-item label="姓名" prop="name">  <el-input v-model="form.name"></el-input>  </el-form-item>  <el-form-item label="年龄" prop="age">  <el-input v-model="form.age"></el-input>  </el-form-item>  <el-form-item label="住址" prop="address">  <el-input v-model="form.address"></el-input>  </el-form-item>  <el-form-item label="电话" prop="phone">  <el-input v-model="form.phone"></el-input>  </el-form-item>  <el-form-item>  <el-button type="primary" @click="submitForm('form')">提交</el-button>  </el-form-item>  </el-form>  </template><script>  
export default {  data() {  return {  form: {  name: '',  age: '',  address: '',  phone: ''  },  rules: {  name: [  { required: true, message: '请输入姓名', trigger: 'blur' },  { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }  ],  age: [  { required: true, message: '请输入年龄', trigger: 'blur' },  { min: 18, max: 100, message: '年龄在 18 到 100 岁之间', trigger: 'blur' }  ],  address: [  { required: true, message: '请输入住址', trigger: 'blur' },  { min: 5, max: 20, message: '长度在 5 到 20 个字符', trigger: 'blur' }  ],  phone: [  { required: true, message: '请输入电话号码', trigger: 'blur' },  { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的电话号码', trigger: 'blur' }  ]  },  apiUrl: 'https://example.com/api/submit' // 后端接口的URL  };  },  methods: {  submitForm(formName) {  this.$refs[formName].validate((valid) => {  if (valid) {  // 表单验证通过,提交表单数据到后端接口  axios.post(this.apiUrl, this.form)  .then((response) => {  // 后端接口返回成功处理逻辑...  console.log('提交成功');  })  .catch((error) => {  // 后端接口返回失败处理逻辑...  console.log('提交失败');  });  } else {  // 表单验证失败,显示错误信息...  console.log('表单验证失败');  return false;  }  });}
}
}</script>  

本地存储

<template><div><h1>Task List</h1><input v-model="newTask" @keyup.enter="addTask" placeholder="Add a new task" /><button @click="removeTask">Delete</button></div></template><script>export default {data() {return {newTask: '',};},methods: {removeTask(index) {console.log(this.newTask,'asadsad')this.tasks.splice(index, 1);// 更新LocalStorage中的任务列表localStorage.setItem('tasks', JSON.stringify(this.newTask));}}};</script>

 

vue本地存储_vue 本地存储-CSDN博客 

http://www.lryc.cn/news/233597.html

相关文章:

  • Qt的委托代理机制
  • OpenCV入门5——OpenCV的算术与位运算
  • 好用的开源项目地址
  • 深度学习(五)softmax 回归之:分类算法介绍,如何加载 Fashion-MINIST 数据集
  • 单稳态中间继电器\UEG/A-2H/220V 8A导轨安装 JOSEF约瑟
  • 2311rust到20版本更新
  • 基于Spring、SpringMVC、MyBatis的漫画网站
  • MySQL数据库八股文
  • 利用WebSocket +MQ发送紧急订单消息,并在客户端收到消息的用户的页面自动刷新列表
  • R语言——taxize(第一部分)
  • 【Spring Cloud】黑马头条 用户服务创建、登录功能实现
  • 聚观早报 |英伟达发布H200;夸克发布自研大模型
  • 15项基本SCADA技术技能
  • Golang 发送邮件
  • 【ARM Trace32(劳特巴赫) 使用介绍 5-- Trace32 通过 JTAG 命令获取数据寄存器 IDCODE的值】
  • Python之while/for,continue/break
  • 卷积神经网络(CNN)衣服图像分类的实现
  • odoo16前端框架源码阅读——env.js
  • 浙大恩特客户资源管理系统 SQL注入漏洞复现
  • ESP32网络开发实例-BME280传感器数据保存到InfluxDB时序数据库
  • C++中sort()函数的greater<int>()参数
  • 2024有哪些免费的mac苹果电脑内存清理工具?
  • 线性表的概念
  • 锐捷练习-ospf虚链路及rip路由相互引入
  • 【机器学习】线性回归算法:原理、公式推导、损失函数、似然函数、梯度下降
  • Word中NoteExpress不显示的问题
  • 连接池的大体介绍,常用配置及在springboot项目中的应用
  • Java之SpringCloud Alibaba【九】【Spring Cloud微服务Skywalking】
  • wpf devexpress设置行和编辑器
  • AdaBoost 算法:理解、实现和掌握 AdaBoost