上节我用element-ui
与 vue-router
实现了页面跳转的功能。vue
回想一下,vue-router
实现组件之间的切换关键也就俩东西,一个router-link
一个router-view
,因此说整体来讲上一节也没学啥。vue-router
props
父组件向子组件传值element-ui
$emit
子组件向父组件传值ui
基于上一节的例子,脑子里构思了一个点击table
的row
,弹出框显示本行信息这样一个画面this
要点:spa
props: ['student']
告诉父组件我(弹出框组件)须要一个student
this.$emit('confirm', this.form)
触发父组件中,弹出框组件上定义的confirm
事件,并将this.form
传递过去student-list-info
组件完整代码:3d
<template> <div> <el-button icon="el-icon-more" @click="dialogFormVisible = true" circle></el-button> <el-dialog title="查询" :visible.sync="dialogFormVisible"> <el-form :model="student"> <el-form-item label="姓名"> <el-input v-model="student.name"></el-input> </el-form-item> <el-form-item label="性别"> <el-input v-model="student.sex"></el-input> </el-form-item> <el-form-item label="年龄"> <el-input v-model.number="student.age" type="number"></el-input> </el-form-item> </el-form> <div slot="footer" class="dialog-footer"> <el-button @click="dialogFormVisible = false">取 消</el-button> <el-button type="primary" @click="doConfirm(student)">确 定</el-button> </div> </el-dialog> </div> </template> <script> export default { name: 'student-list-info', props: ['student'], data () { return { dialogFormVisible: false } }, methods: { doConfirm (student) { this.$emit('confirm', student) this.dialogFormVisible = false } } } </script> <style scoped> </style>
student-list
页面须要注意的只有这里:
<student-list-info style="float: left" @confirm="onConfirm"
:student="this.student"
></student-list-info>code
:student
:中的student
对应props: ['student']
中的student
component
@confirm
:@后面的confirm
对应this.$emit('confirm', this.form)
中的confirm
orm
完整代码:
<template> <div> <el-row> <student-list-info style="float: left" @confirm="onConfirm" :student="this.student"></student-list-info> </el-row> <hr> <h3>学员列表</h3> <el-table :data="tableData" @row-click="onRowClick" border stripe style="width: 100%"> <el-table-column prop="name" label="姓名" width="180"> </el-table-column> <el-table-column prop="sex" label="性别" width="180"> </el-table-column> <el-table-column prop="age" label="年龄"> </el-table-column> </el-table> </div> </template> <script> import studentListInfo from './student-list-info' export default { name: 'student-list', components: { studentListInfo }, data () { return { tableData: [{ name: '张楚岚', sex: '男', age: '23' }, { name: '冯宝宝', sex: '女', age: '99' }, { name: '赵方旭', sex: '男', age: '59' }, { name: '肖自在', sex: '男', age: '36' } ], student: { name: '', sex: '', age: 0 } } }, methods: { onConfirm (item) { this.tableData.push(item) }, onRowClick (row) { this.student = { name: row.name, sex: row.sex, age: row.age } } } } </script> <style scoped> </style>
查看功能一直没有思路,只能先记录一下如今的想法,拿已有的知识来实现他啦
先选中要查看的行,而后点击按钮展现选中的学员信息。
如今的能力真的颇有限,再加上知识面太窄,目前没有找到好的方式能够直接点击行弹出表单信息而不报错的方式,不过我相信用不了多久就能够实现啦,1点了,累,睡啦...