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
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
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 | |
| 0.0.7 | >=2 | MIT | |
| 0.0.6 | >=2 | MIT | |
| 0.0.5 | >=2 | MIT | |
| 0.0.4 | >=2 | MIT | |
| 0.0.3 | >=2 | MIT | |
| 0.0.2 | >=2 | MIT | |
| 0.0.1 | >=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 | |
| 0.0.1-alpha.12 | >=2 | MIT | |
| 0.0.1-alpha.11 | >=2 | MIT | |
| 0.0.1-alpha.10 | >=2 | MIT | |
| 0.0.1-alpha.9 | >=2 | MIT | |
| 0.0.1-alpha.8 | >=2 | MIT | |
| 0.0.1-alpha.6 | >=2 | MIT | |
| 0.0.1-alpha.5 | >=2 | MIT | |
| 0.0.1-alpha.3 | >=2 | MIT | |
| 0.0.1-alpha.2 | >=2 | MIT | |
| 0.0.1-alpha.1 | >=2 | MIT | |
| 0.0.1-alpha.0 | >=2 | MIT |