4.其他的都可以放到Component装饰器里
import { Component, Prop, Vue, Watch, Emit} from "vue-property-decorator";
Component.registerHooks([ "beforeRouteEnter" 'beforeRouteLeave', 'beforeRouteUpdate' ]);
@Component({
mixins: [],
props: {
firstName: String,
lastName: String
components: {
'component-a': ComponentA
export default class about extends Vue {
@Prop() propA:string
@Prop() propB:number
@Prop({ default: "123" }) private propB3: string;
private name: string = "liu";
private num: number = 1;
clickFunc() {
console.log("点击", this.name, this.num);
@Watch("num", { immediate: true })
watchNum(newVal: number) {
console.log(newVal);
get comput1() {
return "computed " + this.num;
created(){
console.log('created')
beforeRouteLeave(to, from, next) {
console.log(to, from)
next();
vuex-class:
安装:npm i vuex-class
原用法:如名为user的module模块
this.$store.state.user.token
this.$store.getters['user/getToken']
this.$store.commit('user/setToken','commit')
this.$store.dispatch('user/updateToken','dispatch')
vuex-class用法
import { State, Mutation, Action } from "vuex-class";
@State("token") stateToken;
@Mutation("setToken") MutationToken;
@Action("updateToken") ActionToken;
this.stateToken
this.MutationToken("MutationToken")
this.ActionToken('ActionToken')
vuex-class module时用法, 列如user和person的module
import { namespace } from 'vuex-class';
const user = namespace('user');
const person = namespace('person');
export default class vuexModules extends Vue {
@person.State(state => state.name) stateName: string;
@user.State((state) => state.token) stateToken;
@user.Getter('getToken') GetterToken;
@user.Mutation("changeToken") MutationToken;
@user.Action("updateToken") ActionToken;
created() {
console.log(this.stateName)
console.log(this.stateToken)
this.GetterToken
this.MutationToken('MutationToken')
this.ActionToken('ActionToken')
复制代码