Skip to content

How to write code of components inside component? #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dlintw opened this issue Dec 12, 2017 · 5 comments
Closed

How to write code of components inside component? #207

dlintw opened this issue Dec 12, 2017 · 5 comments

Comments

@dlintw
Copy link

dlintw commented Dec 12, 2017

I've a vue file like following, named as 'MainPage.vue', how to convert it into class component?

<script lang='ts'>
import MyForm from '@/components/MyForm'
import MyList from '@/components/MyList'
export default {
  name: 'main-page',
  components: {MyForm, MyList}
}
@ktsn
Copy link
Member

ktsn commented Dec 12, 2017

Hi, please use the the official forum or community chat to ask usage questions. The issue list of this repo is exclusively for bug reports and feature requests. Thanks!

@ktsn ktsn closed this as completed Dec 12, 2017
@dlintw
Copy link
Author

dlintw commented Dec 13, 2017

I've posted here, nobody reply.
https://forum.vuejs.org/t/how-to-write-code-of-components-inside-component/23458

I'm wondering is this a bug? Or, what's the correct usage? Maybe it should be described on README.md

<script lang="ts">
import Vue from 'vue'
import { Component } from 'vue-property-decorator'
import throttle from 'lodash/throttle'

@Component
export default class MainPage extends Vue {
  components = {MyList, MyForm}
}
</script>

@ktsn
Copy link
Member

ktsn commented Dec 13, 2017

https://github.com/vuejs/vue-class-component/blob/master/README.md#usage

For all other options, pass them to the decorator function.

@Component({
  components: { MyList, MyForm }
})
class MainPage extends Vue {}

@0pt1m1z3r
Copy link

0pt1m1z3r commented May 29, 2018

@ktsn I get an error

[ts]
Argument of type '{ components: { SwPhoneNumber: Vue; SwSvgIcon: Vue; }; }' is not assignable to parameter of type 'VueClass<Vue>'.
  Object literal may only specify known properties, but 'components' does not exist in type 'VueClass<Vue>'. Did you mean to write 'component'?
(property) ComponentOptions<V, DefaultData<V>, DefaultMethods<V>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<string, any>>.components: {
    [key: string]: VueConstructor<Vue> | FunctionalComponentOptions<any, string[] | {
        [x: string]: PropOptions<any> | (() => any) | (new (...args: any[]) => any) | ((() => any) | (new (...args: any[]) => any))[];
    }> | ComponentOptions<never, any, any, any, any, Record<string, any>> | ((resolve: (component: VueConstructor<Vue> | FunctionalComponentOptions<any, string[] | {
        [x: string]: PropOptions<any> | (() => any) | (new (...args: any[]) => any) | ((() => any) | (new (...args: any[]) => any))[];
    }> | ComponentOptions<never, any, any, any, any, Record<string, any>>) => void, reject: (reason?: any) => void) => void | Promise<VueConstructor<Vue> | FunctionalComponentOptions<Record<string, any>, string[] | {
        [x: string]: PropOptions<any> | (() => any) | (new (...args: any[]) => any) | ((() => any) | (new (...args: any[]) => any))[];
    }> | ComponentOptions<never, object | ((this: never) => object), {
        [key: string]: (this: never, ...args: any[]) => any;
    }, {
        [key: string]: any;
    }, Record<string, any>, Record<string, any>> | EsModuleComponent>);
} | undefined

for this code

import SwPhoneNumber from '~/components/SwPhoneNumber/SwPhoneNumber.vue'
import SwSvgIcon from '~/components/SwSvgIcon/SwSvgIcon.vue'

@Component({
  components: {
    SwPhoneNumber,
    SwSvgIcon
  }
})
export default class SwFooter extends Vue {
   ...
}

What am I doing wrong?

@0pt1m1z3r
Copy link

@ktsn Sorry, I solved the problem. #123 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants