Vue 3 Script Setup 代码生成器 - 使用 Ant Design Vue 和 Ref 响应式变量
<template>
<div>
<a-input ref="input" v-model="text"></a-input>
<a-button @click="handleClick">Generate Vue 3 Script Setup Code</a-button>
<a-textarea ref="output" :value="code" rows="10"></a-textarea>
</div>
</template>
<script setup>
import { ref } from 'vue';
const text = ref('');
const code = ref('');
function handleClick() {
const lines = text.value.trim().split('
');
const variables = lines.map(line => {
const [name, initialValue] = line.split('=').map(s => s.trim());
return `const ${name} = ref(${initialValue});`;
});
const script = `
<script setup>
import { ref } from 'vue';
${variables.join('
')}
// Your other functions here
</script>
<p>`;
code.value = script;
}
</script></p>
原文地址: https://www.cveoy.top/t/topic/mEMi 著作权归作者所有。请勿转载和采集!