vue组件间的信息传递

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//父组件
<template>
<div>
<my-button
:name="this.btnName"
:myStyle="myButtonStyle"
@child-say="whatChildSay"></my-button>
<p>子组件传递过来的值了吗?
<span>{{childWords}}</span>
</p>
<div id="myCharts"></div>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
data () {
return {
msg:'',
btnName:'现在是父组件给子组件传递的值',
myButtonStyle:{
border:'1px solid red'
},

},
methods: {
whatChildSay(data1) {
this.childWords = data1
},
},
}
</script>
<style scoped>
body {
font-family: Menlo, Consolas, monospace;
color: #444;
}
span{
color:red
}
#myCharts{
width: 300px;
height:300px
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//子组件
<template>
<div id="myButton" >
<button :style="myStyle" @click="clickMe()"> {{name}}</button>
</div>
</template>
<script >
export default {
name: 'myButton',
components: {},
props:{
name:String,
myStyle:Object
},
data() {
return {
name1:'现在是子组件传回的值啦'
}
},
filters: {},
methods: {
clickMe(){

this.$emit('child-say',this.name1);
}
},
mounted() {
}
}
</script>
<style scoped lang="scss">
button{
background-color: darkseagreen;
border-radius: 20%;
}
</style>

结果图

父组件通过props传值给子组件(可以通过传值修改样式)

avatar


子组件通过 $emit 传值给父组件

avatar

验证

中英文转换–> Validator.addLocale(zh)失效–>VueI18n

errors里元素为空–>待解决

转换数据显示不同CSS

1
2
3
4
5
6
7
8
9
10
11
<el-table-column
prop="state"
label="状态"
width="150"
>
<template scope="scope">
<div :class="{active:scope.row.state == '0'}">
<span>{{scope.row.state == '0'?'冻结':'正常'}}</span>
</div>
</template>
</el-table-column>

一点小问题

参数区别(显示值和不显示)

1
2
editDialog(scope.row)
addtDialog()

数据库内存储性别为Number:0,1 ;前端显示为string:男,女

解决方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<el-select v-model="escortAddData['Sex']" placeholder="性别">
<el-option v-for="sex in sexs" :label="sex.label" :value="sex.value"></el-option>
</el-select>


sexs: [
{
label: '男',
value: 0
}, {
label: '女',
value: 1
}
]