Skip to content

Commit aa602c9

Browse files
author
Julia Bakerink
committed
Successfully modified Typescript component export to include defineComponent import
1 parent c857312 commit aa602c9

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

juliaTest/Test.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<div>
3+
</div>
4+
</template>
5+
6+
<script lang='ts'>
7+
import { defineComponent } from "vue"
8+
import Test2 from '@/components/Test2.vue';
9+
10+
export default defineComponent ({
11+
name: 'Test',
12+
components: {
13+
Test2,
14+
},
15+
});
16+
</script>
17+
18+
<style scoped>
19+
</style>

src/components/ExportComponentMixin.vue

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ export default {
116116
else imports += "mapActions";
117117
imports += ' } from "vuex"\n';
118118
}
119+
// if Typescript toggle is on, import defineComponent
120+
if (this.exportAsTypescript === "on") {
121+
imports += 'import { defineComponent } from "vue"\n';
122+
}
119123
// add imports for children
120124
children.forEach((name) => {
121125
imports += `import ${name} from '@/components/${name}.vue';\n`;
@@ -162,21 +166,27 @@ export default {
162166
}
163167
// concat all code within script tags
164168
// if exportAsTypescript is on, out should be <script lang="ts">
165-
console.log("export as typescript:", this.exportAsTypescript);
166169
let output;
167170
if (this.exportAsTypescript === 'on') {
168171
output = "\n\n<script lang='ts'>\n";
172+
output += imports + "\nexport default defineComponent ({\n name: '" + componentName + "'";
169173
} else {
170174
output = "\n\n<script>\n";
175+
output += imports + "\nexport default {\n name: '" + componentName + "'";
171176
}
172-
output += imports + "\nexport default {\n name: '" + componentName + "'";
173177
output += ",\n components: {\n";
174178
output += childrenComponentNames + " },\n";
175179
output += data;
176180
output += computed;
177181
output += methods;
178182
// eslint-disable-next-line no-useless-escape
179-
output += "};\n<\/script>";
183+
if (this.exportAsTypescript === 'on') {
184+
output += "});\n<\/script>";
185+
186+
} else {
187+
output += "};\n<\/script>";
188+
}
189+
180190
console.log('output', output);
181191
return output;
182192
},

0 commit comments

Comments
 (0)