Skip to content

Separate vue component into : *.ts and *.html #8864

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
redplane opened this issue Sep 29, 2018 · 4 comments
Closed

Separate vue component into : *.ts and *.html #8864

redplane opened this issue Sep 29, 2018 · 4 comments

Comments

@redplane
Copy link

Hi,

I'm using vue-cli 3 and typescript to make my own application.
Everything seemed to be fine until I separated my module into parts: template file and logic file.
I have a component like this:

  • master-layout.component.ts
@Component({
    name: 'master-layout',
    template: require('html-loader!./master-layout.component.html')
})
export default class MasterLayoutComponent extends Vue {
}
  • master-layout.component.html
<div>
    <router-view/>
</div>

Actually, when this component was combined into one *.vue file, it ran smoothly.
But I want to separate the module into 2 parts because in future, code can be longer and longer, therefore, it is hard to track the issue if available.

When I ran the application after changing my code like above, one error was thrown to me:

You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

Can anyone help ?

Thanks,

@vue-bot
Copy link
Contributor

vue-bot commented Sep 29, 2018

Hello, your issue has been closed because it does not conform to our issue requirements. In order to ensure every issue provides the necessary information for us to investigate, we require the use of the Issue Helper when creating new issues. Thank you!

@vue-bot vue-bot closed this as completed Sep 29, 2018
@Justineo
Copy link
Member

You should still use your .vue file as entry point of a component and include a script tag with src attribute pointing to the separated script file.

@viT-1
Copy link

viT-1 commented Oct 15, 2019

@Justineo It is not true. Nowadays we can testing vue components without .vue files but vue-class-component with imported template (by html-loader-jest not jest-transform-stub).

@rhengles
Copy link

For anyone else coming here from search to separate your components into script, template and style files, I have a working solution in this PR:

#8807

See also the rationale in this issue:

#8106

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

5 participants