Компонент класса Vue - это относительно новый способ написания однофайловых компонентов.Это выглядит так:
import Vue from 'vue'
import Component from 'vue-class-component'
// The @Component decorator indicates the class is a Vue component
@Component({
// All component options are allowed in here
template: '<button @click="onClick">Click!</button>'
})
export default class MyComponent extends Vue {
// Initial data can be declared as instance properties
message: string = 'Hello!'
// Component methods can be declared as instance methods
onClick (): void {
window.alert(this.message)
}
}
Вот некоторые ссылки на него:
https://vuejs.org/v2/guide/typescript.html#Class-Style-Vue-Components https://github.com/vuejs/vue-class-component
Однако,никто из них не объясняет, как писать фильтры в этом синтаксисе.Если я попробую следующий код в моем шаблоне:
{{ output | stringify }}
И затем попытаюсь написать фильтр как метод класса, например:
@Component
export default class HelloWorld extends Vue {
// ... other things
stringify(stuff: any) {
return JSON.stringify(stuff, null, 2);
}
}
Я получу следующую ошибку:
Как правильно добавить фильтр в этот новый синтаксис?