我是靠谱客的博主 沉静老鼠,这篇文章主要介绍Vue之props 配置详解,现在分享给大家,希望可以做个参考。

复制代码
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
46
47
48
49
50
51
52
53
<template> <div class="demo"> <h1>{{ msg}}</h1> <h2>学生姓名:{{name}}</h2> <h2>学生性别:{{sex}}</h2> <h2>学生的年龄:{{myage+1}}</h2> <button @click="changeAge">点我修改数据</button> </div> </template> <script> export default { name: 'Student', data() { return { msg: '王者爱好者', myage:this.age } }, methods: { changeAge(){ this.myage=24 } }, //简单接收 // props:['name','age','sex'] //接收的同时对数据进行类型的限制 // props:{ // name:String, // age:Number, // sex:String, // } //接收数据的同时对数据:进行类型的限定+默认值的指定+必要性的限制 props: { name: { type: String, //name的类型 required: true, //name是必要的 }, age: { type: Number, default:22 }, sex: { type: String, required: true } } } </script>
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<template> <div> <Student name="张三" sex="男" :myage="20"/> </div> </template> <script> //引入Student组件 import Student from './components/Student.vue' export default { name: 'App', components: { Student } } </script>

总结

本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注靠谱客的更多内容!

最后

以上就是沉静老鼠最近收集整理的关于Vue之props 配置详解的全部内容,更多相关Vue之props 内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(149)

评论列表共有 0 条评论

立即
投稿
返回
顶部