GithubHelp home page GithubHelp logo

dream2023 / vue-run-sfc Goto Github PK

View Code? Open in Web Editor NEW
216.0 4.0 45.0 1.7 MB

Vue DEMO利器, 在线运行 & 编辑 Vue 单文件

Home Page: https://vue-run-sfc.netlify.com/

JavaScript 12.42% Vue 62.42% CSS 23.85% HTML 1.32%
vue-run-sfc vue-run vue-sfc vue-runner vue-code-editor

vue-run-sfc's Introduction

vue-run-sfc | Vue DEMO 利器, 在线运行 & 编辑 Vue 单文件

介绍

我一直在思考 🤔 怎么的 Vue 文档交互才是好的 👍, 后来得出的结论是:

  • 能看代码
  • 能看效果
  • 能在线编辑代码, 并实时预览结果

能做到前 2 点的 Vue 组件不少, 但能做到第 3 点, 并对文档的 DEMO 编写做优化处理的并不多, 所以才有了vue-run-sfc.

DEMO

https://vue-run-sfc.netlify.com/

特性

  • 在线预览和编辑 Vue 单文件
  • 错误提示
  • 全屏模式
  • 支持 sass / scss / less / stylus 预处理器

image

生态

安装

yarn add vue-run-sfc # npm install vue-run-sfc --save

使用

全局注册

import VueRunSfc from "vue-run-sfc";

Vue.use(VueRunSfc, {
  // 全局配置(非必填),  具体属性含义参考 `props` 说明
  // 注意 全局的 和 局部的 `cssLabs` 和 `jsLabs` 是 merge的关系, 不是替换
  cssLabs: ["https://unpkg.com/[email protected]/normalize.css"],
  jsLabs: ["https://cdn.jsdelivr.net/npm/[email protected]/lib/index.js"],
  row: true,
  reverse: true,
  height: "400px",
  open: true,
  isHideHeader: false,
  themeColor: "green"
});

局部注册

<script>
  import { VueRunSfc } from "vue-run-sfc";

  export default {
    components: { VueRunSfc }
  };
</script>

示例

<template>
  <vue-run-sfc
    :js-labs="jsLabs"
    :css-labs="cssLabs"
    title="测试DEMO"
    :open="true"
    :code="code"
  ></vue-run-sfc>
</template>

<script>
  export default {
    data() {
      return {
        jsLabs: ["https://cdn.jsdelivr.net/npm/[email protected]/lib/index.js"],
        cssLabs: [
          "https://cdn.jsdelivr.net/npm/[email protected]/lib/theme-chalk/index.css"
        ],
        code: `<template>
<div>
  <h1>{{ title }}</h1>
  <div><el-button type="primary" @click="handleClick">点一下, 玩一年</el-button></div>
</div>
</template>
<script>
export default {
  data() {
    return {
      title: "宝刀屠龙"
    }
  },
  methods: {
    handleClick() {
      this.$message.success('装备不花一分钱')
    }
  }
};
<\/script>
<style>
  body {color: #409EFF;}
</style>`
      };
    }
  };
</script>

props 属性说明

props: {
  /**
   * 代码
   * @example: '<template><div>123</div></template>'
   */
  code: String,

  /**
   * js 库
   * @example: ['https://unpkg.com/element-ui/lib/index.js']
   */
  jsLabs: [String, Array],

  /**
   * css 库
   * @example: ['https://unpkg.com/element-ui/lib/theme-chalk/index.css']
   */
  cssLabs: [String, Array],

  /**
   * js 字符串
   * @example: 'alert(1)'
   */
  js: [Array, String],

  /**
   * css 字符串
   * @example: 'body { color: red }'
   */
  css: [Array, String],

  /**
   * 主体色
   * 默认值: #409eff
   */
  themeColor: {
    type: String,
    default: '#409eff'
  },

  /**
   * 边框色
   * 默认值: #eaeefb
   */
  themeBorderColor: {
    type: String,
    default: '#eaeefb'
  },

  /**
   * 代码编辑器和效果预览排列方式
   * 当为 false 时, 上下排列
   * 当为 true 时, 左右排列
   */
  row: Boolean,

  /**
   * 当 `row` 为 true 时, 编辑区和展示区上下位置
   * 当为 false 时, 编辑器在下, 展示区在上
   * 当为 true 时, 编辑器在上, 展示区在下
   */
  reverse: Boolean,

  /**
   * 标题
   * @example: '测试demo'
   */
  title: String,

  /**
   * 高度
   * @example: '400px'
   */
  height: String,

  /**
   * 初始加载是否打开编辑区
   * 当为 false 时, 默认是关闭编辑区
   * 当为 true 时, 默认是打开编辑区
   */
  open: Boolean,

  /**
   * 是否隐藏头部
   */
  isHideHeader: Boolean
}

相关链接

vue-run-sfc's People

Contributors

dream2023 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vue-run-sfc's Issues

Error when initializing vue-run-sfc

错误截图:

image

iframe.contentWindow.Vue.options = merge(Vue.options, iframe.contentWindow.Vue.options)

像是取不到 Vue ? Element UI 注册失败?

image

image

demo 代码

<template>
    <div>
      <el-form
        ref="generateForm"
        label-suffix=":"
        size="small"
        :model="models"
        :rules="rules"
        label-position="right"
        label-width="100px "
      >
      <el-form-item label="单行文本" prop="input_1588480286000_38712">
        <el-input
        type="text"
        v-model="dataModel.input_1588480286000_38712"
        placeholder="请输入"
        :style="{width:'100%'}"
        :disabled="false"
      ></el-input>
      </el-form-item>
  
      <el-form-item label="多行文本" prop="textarea_1588480300000_98455">
        <el-input
        type="textarea"
        :rows="5"
        v-model="dataModel.textarea_1588480300000_98455"
        placeholder="请输入"
        :style="{width:'100%'}"
        :disabled="false"
        ></el-input>
      </el-form-item>
  </el-form>
    </div>
  </template>
<script>
    export default {
      name:'form-builder',
        data() {
          return {
            models: {"input_1588480286000_38712":"","textarea_1588480300000_98455":""},
            rules: {"input_1588480286000_38712":[{"type":"string","message":"单行文本格式不正确"}],"textarea_1588480300000_98455":[]},
            dataModel: {"input_1588480286000_38712":"","textarea_1588480300000_98455":""},
          };
        },
        created() {
            console.log("***SUCCESS***");
        },
        methods: {}
    }
    </script>

自己使用就不对,在在线demo用代码片段是可以正常渲染的。

"vue-run-sfc": "^1.4.0",

Vue.use(VueRunSfc, {
  jsLabs: ['https://cdn.jsdelivr.net/npm/[email protected]/lib/index.js'],
  cssLabs: [
    'https://unpkg.com/[email protected]/normalize.css',
    'https://cdn.jsdelivr.net/npm/[email protected]/lib/theme-chalk/index.css',
  ],
  row: false,
  reverse: true,
  isHideHeader: false,
});
<vue-run-sfc title="测试DEMO" :open="false" :code="code"></vue-run-sfc>

\

太棒了

用这个来测试一些新功能,太好了

example代码引入依赖会报错

我在jslib利用引入了我需要的npm包的cdn地址,但我在example的code里面使用import xxx from 'xxx',会报错显示require is not defined

Demo报错,el-button无法正常显示:Error: Unknown custom element: - did you register the component correctly?

是需要注册KtButton吗,element库已经全局引入了

Error: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.
at Vue.config.warnHandler (http://localhost:10800/:7:63)
at warn (https://cdn.jsdelivr.net/npm/vue/dist/vue.js:632:28)
at createElm (https://cdn.jsdelivr.net/npm/vue/dist/vue.js:5933:13)
at createChildren (https://cdn.jsdelivr.net/npm/vue/dist/vue.js:6048:11)
at createElm (https://cdn.jsdelivr.net/npm/vue/dist/vue.js:5949:11)
at createChildren (https://cdn.jsdelivr.net/npm/vue/dist/vue.js:6048:11)
at createElm (https://cdn.jsdelivr.net/npm/vue/dist/vue.js:5949:11)
at Vue.patch [as patch] (https://cdn.jsdelivr.net/npm/vue/dist/vue.js:6509:11)
at Vue._update (https://cdn.jsdelivr.net/npm/vue/dist/vue.js:3946:21)
at Vue.updateComponent (https://cdn.jsdelivr.net/npm/vue/dist/vue.js:4067:12)

预览 bug

<el-pagination
      :current-page="0"
      :page-sizes="[100, 200, 300, 400]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400">
</el-pagination>

预览分页时,分页下拉框无法正常显示

demo中的vue不支持原生组件

当使用vuepress-plugin-run时,文档中Vue.options.components如下,像Transition等原生组件都在原型链上

image

但vue-run-sfc-preview组件中执行了如下合并,导致demo中的Vue丢失了原生组件

image

不知道这个合并有何作用,建议干掉

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.