Saperate the script in vue files to .ts files.

hannanmumtaz
0
hannanmumtaz
commented 3 years ago

Hi guys.

Is it pobbile to split .vue files under /pages and keep the script in .ts file and the template in .vue files.

am trying to split the html and the script part.

the /pages can have
/pages/index.vue
/pages/index.ts

index.vue - can have reference to script

<template>

Nuxt TypeScript Starter
Selected Person: {{selectedPerson.first_name}} {{selectedPerson.last_name}} is #{{selected}}
<Card :person="person"></Card>

</template>
<script src="./index.ts"></script>

is the above currently possible ?

0
qm3ster
383
qm3ster
commented 3 years ago

Typically yes, have you tried it already?
I think you have to still set lang tho.

<script lang="ts" src="./index.ts" />
0
hannanmumtaz
0
hannanmumtaz
commented 3 years ago

ah, lang="ts" did the job, i was thinking it will infer the type from the filename, all good now, thanks for your help @qm3ster :)

0
qm3ster
383
qm3ster
commented 3 years ago

I imagine that could be the case, but apparently it isn't.
Not mentioned anywhere either: [1] [2] [3]
Maybe file an issue or PR the documentation if you have the time.

0
lsotoangeldonis
0
lsotoangeldonis
commented 10 months ago

Hi, I'm having an issue with the method suggested,

<script lang="ts" src="./navbarCategoriesComponent.ts"></script>
<style lang="scss" src="./navbarCategoriesComponent.scss" scoped></style>

    <template>
        <div class="container">HELLO</div>
    </template>

This is giving me this error:

image

thanks in advance.

0
qm3ster
383
qm3ster
commented 10 months ago

@lsotoangeldonis what's in navbarCategoriesComponent.ts?

0
Informations
Question โ€ข Unresolved
#c32 - Created 3 years ago