gaoshp
2024-06-13 fd7586c8d91473d2850af1e48b12f1a289e6b8d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<template>
    <el-main>
        <el-alert title="感谢codeMirror组件" type="success" style="margin-bottom:20px;"></el-alert>
        <el-row :gutter="15">
            <el-col :lg="24">
                <el-card shadow="never" header="JSON">
                    <sc-code-editor ref="editor" v-model="json" mode="javascript" :height="200"></sc-code-editor>
                    <div style="margin-top: 15px;">
                        <el-button type="primary" @click="getCode">获取v-model</el-button>
                        <el-button type="primary" @click="getValue">getValue()</el-button>
                        <el-button type="primary" @click="setValue">setValue()</el-button>
                    </div>
                </el-card>
            </el-col>
            <el-col :lg="12">
                <el-card shadow="never" header="javascript Darcula主题">
                    <sc-code-editor v-model="js" mode="javascript" theme="darcula"></sc-code-editor>
                </el-card>
            </el-col>
 
            <el-col :lg="12">
                <el-card shadow="never" header="SQL">
                    <sc-code-editor v-model="sql" mode="sql"></sc-code-editor>
                </el-card>
            </el-col>
        </el-row>
    </el-main>
</template>
 
<script>
    import { defineAsyncComponent } from 'vue';
    const scCodeEditor = defineAsyncComponent(() => import('@/components/scCodeEditor'));
 
    export default {
        name: "codeeditor",
        components: {
            scCodeEditor
        },
        data(){
            return {
                json:
`{
    "name": "SCUI",
    "menu": [
        {
            "title": "VUE 3",
            "type": true,
            "link": "https://v3.cn.vuejs.org"
        },
        {
            "title": "elementplus",
            "type": false,
            "link": "https://element-plus.gitee.io"
        }
    ]
}`,
                js:
`// Demo code (the actual new parser character stream implementation)
function StringStream(string) {
    this.pos = 0;
    this.string = string;
}`,
                sql:
`SELECT \`author\`, \`title\` FROM \`posts\`
WHERE \`status\` = 'draft' AND \`author\` IN('author1','author2')
ORDER BY \`created_at\` DESC, \`id\` DESC LIMIT 0, 10;`
            }
        },
        methods: {
            getCode(){
                this.$message("请查看控制台")
                console.log(this.json)
            },
            getValue(){
                this.$message("请查看控制台")
                var v = this.$refs.editor.coder.getValue()
                console.log(v)
            },
            setValue(){
                var v = `{"key":"newValue"}`
                this.$refs.editor.coder.setValue(v)
            }
        }
    }
</script>
 
<style>
</style>