【element+vue】点击加号增加一行,点击减号删除一行

效果:

代码实现:

页面部分: vue+element

备注:v-if =“i>0” (保证第一行不出现减号)

 <div v-for="(item,i) in studentList">
   <el-form-item label="学生:" prop="name">
     <el-input v-model="studentList[i].name" clearable placeholder="姓名"></el-input>
   </el-form-item>
   <el-form-item prop="age">
      <el-input v-model="studentList[i].age" clearable placeholder="年龄"></el-input>
   </el-form-item>
   <el-button circle icon="el-icon-plus" @click="addList()"></el-button>
   <el-button circle icon="el-icon-minus" @click="subList(i)" v-if="i>0"></el-button>
 </div>

数据部分:赋一组空值,页面自动显示第一行

 data() {
       return {
         studentList: [
           {name: '', age: ''}
         ]
       }
     }

函数部分:点击加号,给数组新增一组空值,新增一行;点击减号,将行号传入,删除当前行

methods: {
        //加号
        addList() {
            this.studentList.push({name: '', age: ''})
        },
        //减号
        subList(index) {
          this.studentList.splice(index, 1)
        }
 }

以下是一个.NET 6.0 + Element + Vue2的框架搭建步骤: 1. 首先安装.NET 6.0,可以从官网下载安装包并按照提示进行安装。 2. 创建一个新的.NET 6.0 Web项目,可以选择ASP.NET Core Web Application模板并选择API模板。 3. 在项目中安装Vue.jsElement UI,可以使用npm包管理器或者yarn进行安装。 ``` npm install vue npm install element-ui ``` 4. 在项目中创建一个Vue组件,并在组件中引入Element UI的组件,例如: ```vue <template> <div> <el-button @click="showDialog">打开对话框</el-button> <el-dialog :visible.sync="dialogVisible"> <span>这是一个对话框</span> <span slot="footer" class="dialog-footer"> <el-button @click="dialogVisible = false">取 消</el-button> <el-button type="primary" @click="dialogVisible = false">确 定</el-button> </span> </el-dialog> </div> </template> <script> import { ElButton, ElDialog } from 'element-ui'; export default { components: { ElButton, ElDialog, }, data() { return { dialogVisible: false, }; }, methods: { showDialog() { this.dialogVisible = true; }, }, }; </script> ``` 5. 在.NET项目中添加对Vue组件的路由支持,例如: ```csharp app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapFallbackToFile("index.html"); }); ``` 6. 最后在.NET项目中创建一个HTML页面并引入Vue组件,例如: ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>My App</title> </head> <body> <div id="app"></div> <script src="~/js/app.js"></script> </body> </html> ``` 7. 运行.NET项目并在浏览器中查看页面,应该可以看到一个包含Element UI组件的页面。 希望这个步骤能够帮助你快速搭建一个.NET 6.0 + Element + Vue2的框架。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

咕之

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值