基于路由支持开发单页应用
在开发单页应用时,Vue 提供了丰富的功能和工具,下面将详细介绍如何使用 Vue 开发具有路由支持的单页应用。
1. 组件属性与数据传递
在 Vue 中,我们可以为组件属性提供默认值。例如,为 msg 属性提供默认值:
@Prop({default: "The message will go here"}) private msg: string;
这是使用 @Prop() 属性级装饰器声明 HelloWorld 组件接受一个 msg 属性。另外,也可以使用 @Component() 装饰器的 props 属性来实现:
@Component({
props: {
msg: {
default: "The message will go here"
}
}
})
export default class HelloWorld extends Vue { }
如果父组件没有为 msg 属性赋值,例如 <HelloWorld /> ,则会渲染默认属性值。
使用 props </
超级会员免费看
订阅专栏 解锁全文
1580

被折叠的 条评论
为什么被折叠?



