feat: code-view”

This commit is contained in:
wf 2024-06-06 17:29:35 +08:00
parent 1689a497d0
commit a0915c9cdd
2 changed files with 12 additions and 5 deletions

View File

@ -18,6 +18,7 @@ import { vue } from "@codemirror/lang-vue";
defineOptions({ name: "CodeView" }); defineOptions({ name: "CodeView" });
// Props
interface Props { interface Props {
type?: "javascript" | "vue" | "json"; type?: "javascript" | "vue" | "json";
codeJson: string; codeJson: string;
@ -25,13 +26,13 @@ interface Props {
// withDefaultsdefineProps // withDefaultsdefineProps
// https://cn.vuejs.org/guide/typescript/composition-api.html#typing-component-props // https://cn.vuejs.org/guide/typescript/composition-api.html#typing-component-props
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
type: "javascript", // type: "javascript", //
codeJson: "" // codeJson: "" //
}); });
// //
// \t // \t
const codeValue = computed(() => JSON.stringify(props.codeJson, null, "\t")); const codeValue = computed(() => props.codeJson);
// //
const config = ref({ const config = ref({

View File

@ -84,13 +84,13 @@
<a-form-item> <a-form-item>
<a-space> <a-space>
<a-button html-type="submit">提交</a-button> <a-button html-type="submit">提交</a-button>
<a-button @click="$refs.formRef.resetFields()">重置</a-button> <a-button @click="onReset">重置</a-button>
</a-space> </a-space>
</a-form-item> </a-form-item>
</a-form> </a-form>
</a-col> </a-col>
<a-col :span="12"> <a-col :span="12">
<CodeView :code-json="form" /> <CodeView :code-json="codeJson" />
</a-col> </a-col>
</a-row> </a-row>
</div> </div>
@ -100,7 +100,8 @@
const handleSubmit = ({ values, errors }: any) => { const handleSubmit = ({ values, errors }: any) => {
console.log("values:", values, "\nerrors:", errors); console.log("values:", values, "\nerrors:", errors);
}; };
// \t
const codeJson = computed(() => JSON.stringify(form, null, "\t"));
const form = reactive({ const form = reactive({
size: "medium", size: "medium",
name: "", name: "",
@ -189,6 +190,11 @@ const treeData = [
] ]
} }
]; ];
const formRef = ref();
const onReset = () => {
formRef.value.resetFields();
};
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>