vue3 props template使用

vue3 props template使用


2024年5月4日发(作者:)

vue3 props template使用

x

### 一、props的使用

1、props可以将外部属性传递给内部组件,基本用法如下:

```

ent('child', {

props: ['msg'],

template: '{{ msg }}'

})

```

2、props的类型

```

props: {

// 基础类型

title: String,

// 对象

obj: {

type: Object,

default: () => {

return { isShow: false }

}

- 1 -

},

// 数组

arr: {

type: Array,

default: () => {

return []

}

},

// 基础类型的别名

count: {

type: Number,

default: 0

},

}

```

3、使用v-bind动态绑定props:

```

```

4、props校验

```

props: {

- 2 -

ttitle: {

t type: String,

t required: true

t}

}

```

### 二、template的使用

1、模板语法

template模板中语法说明:

* (1)以双大括号{{ }}表示模板变量,只能用于表达式,不能用

于控制结构;

* (2)v-bind绑定表达式,v-bind绑定属性;

* (3)v-if条件分支;

* (4)v-for循环;

* (5)v-on事件绑定。

- 3 -


发布者:admin,转转请注明出处:http://www.yc00.com/news/1714770192a2512304.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信