velay

vue page and fragments
644 3
Install
npm install velay
Latest Version:1.0.2
Vue:2
License:MIT
Last Updated:Dec 3, 2022
Links: GitHub  ·  npm
Maintainer: thundernet8

Velay

使用 TypeScript 以 OOP 的方式写 Vue 和 Vuex store.

Requirements

// tsconfig.json

{
    "compilerOptions": {
        ...
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        ...
    }
}

Usage

Write Store Class

// my-store.ts
import { Injectable, State, StoreService } from 'velay';

export class MyStoreService extends StoreService {
    @State
    count: number = 0;

    @State
    title: string = 'hello, velay';

    @State
    list: { name: string; count: number }[] = [{ name: 'velay1', count: 1 }, { name: 'velay2', count: 2 }];

    changeTitle(title: string) {
        this.title = title;
    }

    addCount() {
        this.count = this.count + 1;
    }
}

Write Component

// my-component.vue
<template>
    <div>
        <h2>{{ store.title }}{{ store.count }}</h2>
        <ul>
            <li v-for="(item, index) in store.list" :key="index">
                <div>{{ item.name }}-{{ item.count }}</div>
            </li>
        </ul>
        <button @click="store.changeTitle('new hello')">Change title</button>
        <button @click="store.addCount">Add count</button>
    </div>
</template>
<script lang="ts">
import { Vue, Component } from 'velay';
import { MyStoreService } from './my-store';

@Component({})
export default class MyComponent extends Vue {
    constructor(private readonly store: MyStoreService) {
        super();
    }

    mounted() {
        console.log('store', this.store);
    }
}
</script>

More

Debug

开启 debug

Velay.config.debug = true;

Vetur

开启模板语法检查,配合 velay 获得更佳的强类型校验

{
    "vetur.experimental.templateInterpolationService": true
}

Augmenting Vue Types

https://vuejs.org/v2/guide/typescript.html#Augmenting-Types-for-Use-with-Plugins

Related Packages

spyfu-vuex-helpers

Utility functions for Vuex.

2,459 9
vuex-pathify

Ridiculously simple Vuex setup + wiring

322,817 1,358
direct-vuex

Use and implement your Vuex store with TypeScript types. Compatible with the Vue...

90,286 255
undo-redo-vuex

A Vuex plugin for module namespaced undo and redo functionality. This plugin tak...

9,207 47
vuex-typescript-fsa

The helper which makes vuex more type-safety

7,911

Version History

Version Released Vue License
1.0.2 >=2 MIT
1.0.1 >=2 MIT
1.0.0 >=2 MIT
0.1.0 >=2 MIT
0.0.8 >=2 MIT
Pre-releases (16)
Version Released Vue License
0.0.1-alpha.21 >=2 MIT
0.0.1-alpha.20 >=2 MIT
0.0.1-alpha.16 >=2 MIT
0.0.1-alpha.15 >=2 MIT
0.0.1-alpha.13 >=2 MIT