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

View File

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