import {Options, Vue, Prop} from 'vue-property-decorator';
@Options({})
export default class Test extends Vue {
@Prop() private name:string=""
public activated() {
public created() {
vue-
property-
decorator是由社区根据
vue官方的
vue-class-component开发的,
现在
vue-class-component更新了,原先引入的 Compenots 变成了现在的Options
但是
vue-
property-
decorator的源码并未同步更新,所以在用时就会报错
提示报错后,在node_modules/
vue-
property-
decorator/bin/index.js找到
把前面几行代码改成这样就行
identifier!
如果编译器不能够去除null或undefined,你可以
使用类型断言手动去除。 语法是添加!后缀:identifier!从identifier的类型里去除了null和undefined:
function fixed(name: string | null): string {
function postfix(epithet: string) {
vue-property-decorator的使用方法网上例子很多,可以参考: 使用demo 这里就不说了,主要说一下遇到的问题:
1.使用报错
import {Component, Vue,} from 'vue-property-decorator';
网上大都用的这种,我在vscode中vetur会报:Type ‘typeof import(“D:/work/working/vue-test/node_modules/vue/dist/vue”)’ is not a constructor func
npm install
vue-class-component
vue-
property-
decorator --save-dev
标题首先,我们来说说它们的区别与联系:
1、
vue-
property-
decorator社区出品;
vue-class-component官方出品
2、
vue-class-component提供了
Vue、Component等;
3、
vue-prope...
vue-property-decorator基础教程为什么要使用vue-property-decorator如何使用vue-property-decorator基本写法data中定义数据生命周期钩子函数方法@Component@Prop@Emit计算属性@Watch
为什么要使用vue-property-decorator
vue-property-decorator是在vue-class-component的基础上做了进一步的封装,在TypeScript官方文档 中,官方推荐了vue-class-com
修改package.json中的
vue-
property-
decorator版本
执行npm install --legacy-peer-deps
然后就不会提示有问题了
网上教程都是Component,但是
vue-class-component都换成@Options了…
vue3.0和antdesign一起
使用,ant-design-
vue需要v2的版本,否则当行这样的样式就会出现问题。
import Antd from "ant-design-
vue";
import "ant-design-
vue/dist/antd.css";
const app = createApp(App);
.use(A
参考:https://github.com/kaorun343/vue-property-decorator
怎么使vue支持ts写法呢,我们需要用到vue-property-decorator,这个组件完全依赖于vue-class-component.
首先安装: npm i -D vue-property-decorator
我们来看下页面上代码展示:
<template>
foo:{{foo}}
defaultArg:{{defa...
这节我们继续解析一个叫vue-property-decorator的第三方库,首先可以看它官网的一个介绍:
This library fully depends on [vue-class-component](https://github.com/vuejs/vue-class-component), so please read its README before using this library.
也就是说它是基于vue-class-component库的,在上一篇文章中我们介绍了如何在v