vuejs 动态添加input框的实例讲解
(编辑:jimmy 日期: 2025/10/26 浏览: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">
效果图:
拓展知识: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框的实例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
下一篇:vue.js input框之间赋值方法
