当前位置: 首页 > news >正文

医疗保险网站开通建设汕头seo

医疗保险网站开通建设,汕头seo,页面设计布局,做服装设计兼职的网站一、前言 与link类似 在VUE项目中应用typescript,我们需要引入一个库vue-property-decorator, 其是基于vue-class-component库而来,这个库vue官方推出的一个支持使用class方式来开发vue单文件组件的库 主要的功能如下: metho…

一、前言

与link类似

VUE项目中应用typescript,我们需要引入一个库vue-property-decorator

其是基于vue-class-component库而来,这个库vue官方推出的一个支持使用class方式来开发vue单文件组件的库

主要的功能如下:

  • methods 可以直接声明为类的成员方法
  • 计算属性可以被声明为类的属性访问器
  • 初始化的 data 可以被声明为类属性
  • data、render 以及所有的 Vue 生命周期钩子可以直接作为类的成员方法
  • 所有其他属性,需要放在装饰器中

二、使用

vue-property-decorator 主要提供了多个装饰器和一个函数:

  • @Prop
  • @PropSync
  • @Model
  • @Watch
  • @Provide
  • @Inject
  • @ProvideReactive
  • @InjectReactive
  • @Emit
  • @Ref
  • @Component (由 vue-class-component 提供)
  • Mixins (由 vue-class-component 提供)

@Component

Component装饰器它注明了此类为一个Vue组件,因此即使没有设置选项也不能省略

如果需要定义比如 namecomponentsfiltersdirectives以及自定义属性,就可以在Component装饰器中定义,如下:

import {Component,Vue} from 'vue-property-decorator';
import {componentA,componentB} from '@/components';@Component({components:{componentA,componentB,},directives: {focus: {// 指令的定义inserted: function (el) {el.focus()}}}
})
export default class YourCompoent extends Vue{}

computed、data、methods

这里取消了组件的data和methods属性,以往data返回对象中的属性、methods中的方法需要直接定义在Class中,当做类的属性和方法

@Component
export default class HelloDecorator extends Vue {count: number = 123 // 类属性相当于以前的 dataadd(): number { // 类方法就是以前的方法this.count + 1}// 获取计算属性get total(): number {return this.count + 1}// 设置计算属性set total(param:number): void {this.count = param}
}

@props

组件接收属性的装饰器,如下使用:

import {Component,Vue,Prop} from vue-property-decorator;@Component
export default class YourComponent extends Vue {@Prop(String)propA:string;@Prop([String,Number])propB:string|number;@Prop({type: String, // type: [String , Number]default: 'default value', // 一般为String或Number//如果是对象或数组的话。默认值从一个工厂函数中返回// defatult: () => {//     return ['a','b']// }required: true,validator: (value) => {return ['InProcess','Settled'].indexOf(value) !== -1}})propC:string;
}

@watch

实际就是Vue中的监听器,如下:

import { Vue, Component, Watch } from 'vue-property-decorator'@Component
export default class YourComponent extends Vue {@Watch('child')onChildChanged(val: string, oldVal: string) {}@Watch('person', { immediate: true, deep: true })onPersonChanged1(val: Person, oldVal: Person) {}@Watch('person')onPersonChanged2(val: Person, oldVal: Person) {}
}

@emit

vue-property-decorator 提供的 @Emit 装饰器就是代替Vue 中的事件的触发$emit,如下:

import {Vue, Component, Emit} from 'vue-property-decorator';@Component({})export default class Some extends Vue{mounted(){this.$on('emit-todo', function(n) {console.log(n)})this.emitTodo('world');}@Emit()emitTodo(n: string){console.log('hello');}}

三 、总结

可以看到上述typescript版本的vue class的语法与平时javascript版本使用起来还是有很大的不同,多处用到class与装饰器,但实际上本质是一致的,只有不断编写才会得心应手

http://www.tj-hxxt.cn/news/59470.html

相关文章:

  • 阿里云机器怎么做网站seo爱站网
  • 泉州专业网站营销今日重点新闻
  • 唐河做网站百度搜索下载
  • 设计师做单页的网站seo网络推广知识
  • 网站排名如何做免费舆情网站下载大全最新版
  • 利用大平台做网站外贸网站推广软件
  • 东莞高埗做网站哪个公司好网络营销教学网站
  • 企业网站建设原则seo推广沧州公司电话
  • 聊城网站优化网络推广seo整站优化方案案例
  • 淘宝优惠券微网站开发知名网页设计公司
  • wordpress导入lofter北京百度seo排名点击软件
  • 东莞厚街做网站软文范文200字
  • 网站规划与设计就业百度推广软件
  • wordpress 运费设置seo整站优化哪家专业
  • 珠海北京网站建设百度快速收录
  • 惠阳网站制作公司国外搜索引擎有哪些
  • 域名哪个网站买最好搜索app下载安装
  • 建设工程的招标网站有哪些网络营销平台有哪些
  • wordpress商城案例seo优化技术排名
  • java做网站的步骤社交媒体营销策略有哪些
  • wordpress 菜单去掉链接百度优化怎么做
  • 地方网站用什么域名天津百度爱采购
  • wordpress 邮箱订阅上海高端seo公司
  • 关于做奶妈的视频网站淘宝关键词搜索排名
  • 重庆建设工程信息网网搜索引擎优化是做什么的
  • 巩义网站建设案例网站制作维护
  • 门户网站目标客户免费推广网站排行榜
  • 个人门户网站备案杭州网站排名提升
  • 网站服务器有问题怎么办啊优化方案的格式及范文
  • 芜湖代理公司注册seo营销软件