Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thundernet8/velay

使用 TypeScript 以 OOP 的方式写 Vue 和 Vuex store.
https://github.com/thundernet8/velay

injection oop vue vuex

Last synced: about 1 month ago
JSON representation

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

Awesome Lists containing this project

README

        

## Velay

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

## Requirements

```json
// tsconfig.json

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

## Usage

### Write Store Class

```ts
// 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

```ts
// my-component.vue


{{ store.title }}{{ store.count }}




  • {{ item.name }}-{{ item.count }}



Change title
Add count

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);
}
}

```

## More

### Debug

开启 debug

```ts
Velay.config.debug = true;
```

### Vetur

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

```json
{
"vetur.experimental.templateInterpolationService": true
}
```

### Augmenting Vue Types

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