fix: 修复 schema 切换时 generator 被旧 config 调用导致白板
根因: activeSchemaId 变化后,ConfigForm 还没 emit 新默认值,generator 就用旧 config 执行了 修复: 在 App.vue 中 watch activeSchemaId,切换时立即用新 schema 默认值重置 config 同时修复 bind.js 中 forwarders.split() 的防御性空值处理
This commit is contained in:
+6
-1
@@ -15,7 +15,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import Sidebar from './components/Sidebar.vue'
|
||||
import ConfigForm from './components/ConfigForm.vue'
|
||||
import CodePreview from './components/CodePreview.vue'
|
||||
@@ -26,6 +26,11 @@ const currentConfig = ref({})
|
||||
|
||||
const currentSchema = computed(() => schemas[activeSchemaId.value])
|
||||
|
||||
// 当 schema 切换时,立即用新 schema 的默认值重置 config
|
||||
watch(activeSchemaId, (newId) => {
|
||||
currentConfig.value = getDefaultValues(schemas[newId])
|
||||
})
|
||||
|
||||
const generatedCode = computed(() => {
|
||||
const gen = generators[activeSchemaId.value]
|
||||
if (!gen) return ''
|
||||
|
||||
@@ -5,6 +5,11 @@ import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
||||
import App from './App.vue'
|
||||
|
||||
const app = createApp(App)
|
||||
|
||||
app.config.errorHandler = (err, instance, info) => {
|
||||
console.error('Vue Error:', err, info)
|
||||
}
|
||||
|
||||
app.use(ElementPlus, { size: 'default' })
|
||||
|
||||
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
||||
|
||||
+1
-1
@@ -174,7 +174,7 @@ export function generateBindConf(config) {
|
||||
lines.push(` recursion ${config.recursion ? 'yes' : 'no'};`)
|
||||
lines.push(``)
|
||||
lines.push(` forwarders {`)
|
||||
const forwarders = config.forwarders.split(';').map((s) => s.trim()).filter(Boolean)
|
||||
const forwarders = (config.forwarders || '').split(';').map((s) => s.trim()).filter(Boolean)
|
||||
forwarders.forEach((f) => {
|
||||
lines.push(` ${f};`)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user