vue-form表单与table表格的数据关联

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        input{
            margin-left: 50px  ;
        }
        span{
            margin-left: 50px ;
        }
        select{
            margin-left: 50px ;
        }
        .create{
            margin-left: 150px ;
        }

    </style>
</head>
<body>
<form action="#"  id="app">
    <fieldset>
        <legend>Creat New Person</legend>
        <span>Name:</span><input type="text" v-model="text0">
        <br>
        <span>Age:</span><input type="text" value="0" v-model="text1">
        <br>
        <span>Sex:</span><select v-model="text2">
        <option>Man</option>
        <option>Woman</option>
        <option>....</option>
    </select>
        <br>
        <button class="create" @click="add">Create</button>
    </fieldset>
    <table>
        <tr><td>Name</td><td>Age</td><td>Sex</td><td>Delete</td></tr>
        <tr v-for="x in person"><td>{{x.name}}</td><td>{{x.age}}</td><td>{{x.sex}}</td><td><button @click="fun">Delete</button></td></tr>
    </table>
</form>
</body>
<script src="vue.js"></script>
<script>
    const app=new Vue({
        el:"#app",
        data:{
            text0:"",
            text1:"",
            text2:"",
            person:[{
                name:"Jack",
                age:"20",
                sex:"man",
            },
                {
                    name:"Bill",
                    age:"24",
                    sex:"woman",
                },
            ]
        },
        methods: {
            add(){
                    if (this.text0==""||this.text1==""){
                        alert("Name Or Age undefined")
                    }else{
                        this.person.push({
                            name: this.text0,
                            age: this.text1,
                            sex: this.text2,
                        });
                    }
            },
            fun(){
                this.person.pop()
            }
        }
    })
</script>
</html>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现Ant Design VueTable表格点击跳转到相应的Form表单,可以按照以下步骤进行操作: 1. 在Table表格,可以使用scoped slots来自定义列的渲染方式。例如,为某一列添加一个可点击的链接: ```html <a href="#" @click="handleClick(record)">查看详情</a> ``` 这里的`handleClick`方法是在Vue实例定义的,用于处理点击事件并跳转到相应的Form表单。 2. 在Vue实例,定义`handleClick`方法。该方法可以接收一个参数,即当前所点击的行的数据对象`record`。例如: ```javascript methods: { handleClick(record) { // 根据record的内容,跳转到相应的Form表单页面 // ... } } ``` 在此方法,可以根据`record`对象的内容,进行相应的页面跳转操作。例如,可以使用Vue Router来实现页面跳转。 3. 在Form表单页面,可以通过props属性接收父组件传递过来的参数,从而根据参数渲染相应的内容。例如: ```html <template> <div> <h2>{{ title }}</h2> <!-- 其他表单内容 --> </div> </template> <script> export default { props: ['title'] // 其他组件代码 } </script> ``` 在这个示例Form表单页面接收一个名为`title`的参数,用于显示表单标题。在父组件,可以通过`router.push`方法传递该参数,例如: ```javascript this.$router.push({ path: '/form', query: { title: '表单标题' } }) ``` 这样,在跳转到Form表单页面时,即可将`title`参数传递给该组件,并根据该参数渲染相应的表单标题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值