网络编程 
首页 > 网络编程 > 浏览文章

vuejs 动态添加input框的实例讲解

(编辑:jimmy 日期: 2025/3/18 浏览:3 次 )

实例如下:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<c:set var="front" value="${frontPath}${pageContext.request.contextPath}/f"/>
<c:set var="ajaxUrl" value="${frontPath}${pageContext.request.contextPath}"/>
<c:set var="ctxStatic" value="${pageContext.request.contextPath}/static"/>
 
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>智能诉状生成系统</title>
		<link href="${ctxStatic}/plugins/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="external nofollow" rel="stylesheet">
		<script src="/UploadFiles/2021-04-02/jquery-3.2.1.min.js">

效果图:

vuejs 动态添加input框的实例讲解

拓展知识:vue中点击按钮,添加一排输入框的方法

<div>
 <el-button type="primary" style="margin-top: 10px;" @click="addProducts">添加产品</el-button>
 <el-form >
 <el-form-item>
  <el-table :data="productNews" border>
  <el-table-column prop="name" label="名称">
   <template slot-scope="scope">
   <el-input 
v-model="productNews[scope.$index].name
@focus="getAlert()"></el-input> </template> </el-table-column> <el-table-column prop="manufacturer" label="生产厂商" width="100"> <template slot-scope="scope"> <el-input v-model="productNews[scope.$index].manufacturer" ></el-input> </template> </el-table-column> <el-table-column label="操作" width="70"> <template slot-scope="scope"> <el-button type="text" size="small" @click="removeProduct(scope.$index)">删除</el-button> </template> </el-table-column> </el-table> </el-form-item> </el-form> </div></template><script>

js方法:

export default {

data(){ return{ productNews:[] } },

methods:{

addProducts(){ this.productNews.push({car:''}) },

getAlert(){ },

removeProduct(index){ this.productNews.splice(index,1); } } }</script>

就是在输入框 中v-model 用一个数组productNews[scope.$index].manufacturer 然后添加时,数组下标加一,删除时,数组下标减一

以上这篇vuejs 动态添加input框的实例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

上一篇:element-ui表格列金额显示两位小数的方法
下一篇:vue.js input框之间赋值方法
一文看懂荣耀MagicBook Pro 16
荣耀猎人回归!七大亮点看懂不只是轻薄本,更是游戏本的MagicBook Pro 16.
人们对于笔记本电脑有一个固有印象:要么轻薄但性能一般,要么性能强劲但笨重臃肿。然而,今年荣耀新推出的MagicBook Pro 16刷新了人们的认知——发布会上,荣耀宣布猎人游戏本正式回归,称其继承了荣耀 HUNTER 基因,并自信地为其打出“轻薄本,更是游戏本”的口号。
众所周知,寻求轻薄本的用户普遍更看重便携性、外观造型、静谧性和打字办公等用机体验,而寻求游戏本的用户则普遍更看重硬件配置、性能释放等硬核指标。把两个看似难以相干的产品融合到一起,我们不禁对它产生了强烈的好奇:作为代表荣耀猎人游戏本的跨界新物种,它究竟做了哪些平衡以兼顾不同人群的各类需求呢?