dword-design/nuxt-route-meta

Meta is not parsed when page component uses mixins

dovca opened this issue · 2 comments

dovca commented

Hi, I'm using class decorators in SFCs. I found a bug in the parsing algorithm. It only accepts page components which extend Vue directly. The parsing fails to find meta when the component uses mixins:

// pages/index.vue

import {Component, mixins} from 'nuxt-property-decorator';
import SomeMixin from '@/mixins/SomeMixin';

@Component({})
export default PageComponent extends mixins(SomeMixin) {
  meta = {foo: 'bar'};
}

May I suggest parsing the @Component decorator options instead like so?: (only if the typescript AST parser allows it)

@Component({meta: {foo: 'bar'}})

@dovca How is the logic behind it if you add meta to both @Component and component body? Is it merged? Or does one have precedence?

dovca commented

@dword-design In a decent IDE like WebStorm, you can get some basic type hints when defining meta in the decorator thanks to this, which does not happen when defining it as a property in the class body. Given this slight advantage, I would personally prefer decorator meta having precedence over component body meta. After all, it wouldn't make sense to define it in both places, since none of them have access to the encapsulating component, which would give it an advantage. That means all data in meta is most likely static and any merging can be done by the code author manually. What are your thoughts on this?