CodeRun 代码运行组件

实现 markdown 中测试编辑运行 js 代码或者 vue 组件

WARNING

特别注意 js 代码行结束需要加分号,建议使用 vscode 插件自动处理。

JS 运行可编辑代码

>{}
let resp = {
  test: 'testjs',
};

return resp;
1
2
3
4
5

Vue 运行编辑组件

>{}
<template>
  <div class="code-index-page">
    <button @click="onTagEvent">点击加消息数</button> {{ the.tag.text }}
  </div>
</template>

<script>
// 在线调试不支持引入
//import { reactive } from 'vue';

export default {
  setup() {
    // 使用外挂方式引入,具体查看demo
    const $plus = window.$plus;
    const { reactive } = $plus.vue;
    // 组件变量
    const the = reactive({
      tag: {
        text: 9,
      },
    });

    /** 标签事件 */
    const onTagEvent = () => {
      console.log('onTagEvent:', the.tag.text);
      the.tag.text = the.tag.text + 1;
    };

    return { the, onTagEvent };
  },
};
</script>

<style lang="less">
.code-index-page {
  button {
    margin: 0.5rem;
  }
}
</style>
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

CodeRun 属性

<CodeRun dll="json" styled="height:20rem" ubb editable>

属性说明类型默认值
editable代码可编辑Booleanfalse
auto初始自动执行Booleanfalse
mini不执行压缩 unmini,默认需要压缩Booleanfalse
ubb不执行解码 ubb,默认需要转换Booleanfalse
styledcode 层样式定义String
lang运行的语言 js vueStringvue
pars初始传入组件绑定的参数-私有参数

组件内包含的代码需要加语言类别,目前只支持 js vue

Last Updated: