npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hep-code-runner/vue2

v2.3.23

Published

Vue 2 code runner component

Readme

@hep-code-runner/vue2

Vue 2 代码运行器组件,基于 Piston API 支持多种编程语言在线执行。

安装

npm install @hep-code-runner/vue2

引入

import { CodeRunner } from "@hep-code-runner/vue2";
import "@hep-code-runner/vue2/dist/style.css";

CodeRunner

用法

<template>
  <CodeRunner />
</template>

<script>
import { CodeRunner } from "@hep-code-runner/vue2";

export default {
  components: { CodeRunner },
};
</script>

Props

| 属性 | 类型 | 默认值 | 说明 | |------|------|--------|------| | pistonUrl | string | '/api/piston' | Piston API 地址 | | token | string | - | 认证 Token(会作为 Authorization 和 id-token Header) | | language | string | 'javascript' | 当前语言 | | code | string | '' | 当前代码 | | theme | 'light' | 'dark' | 'light' | 主题 | | themeColor | string | - | 自定义主题色 | | showLanguageSelector | boolean | true | 显示语言选择器 | | showEditor | boolean | true | 显示代码编辑器 | | editable | boolean | true | 是否可编辑 | | executorLabel | string | '运行' | 运行按钮文字 |

受控模式

Vue 2 不支持多 v-model,使用 .sync 替代:

<template>
  <CodeRunner
    :language.sync="currentLanguage"
    :code.sync="currentCode"
  />
</template>

<script>
export default {
  data() {
    return {
      currentLanguage: 'javascript',
      currentCode: 'console.log("hello")',
    };
  },
};
</script>

Events

| 事件名 | 参数 | 说明 | |--------|------|------| | update:language | language | 语言变化 | | update:code | code | 代码变化 | | execute-start | - | 代码开始执行 | | execute-end | result | 代码执行完成 | | language-change | language, code, snippet | 语言切换,snippet 为新语言的默认代码片段 | | change | code | 代码变化(防抖) |


CodeRunnerDialog

用法

<template>
  <CodeRunnerDialog ref="dialog" title="代码执行器">
    <template #footer="{ close }">
      <button @click="close">取消</button>
      <button @click="handleSave">保存</button>
    </template>
  </CodeRunnerDialog>
</template>

<script>
import { CodeRunnerDialog } from "@hep-code-runner/vue2";

export default {
  components: { CodeRunnerDialog },
  methods: {
    handleSave() {
      this.$refs.dialog.close();
    },
  },
};
</script>

受控模式

<template>
  <button @click="visible = true">打开</button>

  <CodeRunnerDialog
    v-model="visible"
    :language.sync="currentLanguage"
    :code.sync="currentCode"
    title="代码执行器"
    width="800"
    @close="onClose"
  >
    <template #footer="{ close }">
      <button @click="close">取消</button>
      <button @click="handleSave(close)">保存</button>
    </template>
  </CodeRunnerDialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      currentLanguage: 'python',
      currentCode: 'print("hello")',
    };
  },
  methods: {
    onClose() {},
    handleSave(close) {
      close();
    },
  },
};
</script>

Props

| 属性 | 类型 | 默认值 | 说明 | |------|------|--------|------| | value / v-model | boolean | false | 控制显隐 | | :language.sync | string | 'javascript' | 当前语言 | | :code.sync | string | '' | 当前代码 | | title | string | '代码执行器' | 弹窗标题 | | width | string | number | 800 | 弹窗宽度 | | pistonUrl | string | '/api/piston' | Piston API 地址 | | token | string | - | 认证 Token(会作为 Authorization 和 id-token Header) | | theme | 'light' | 'dark' | 'light' | 主题 | | themeColor | string | - | 自定义主题色 | | showLanguageSelector | boolean | true | 显示语言选择器 | | showEditor | boolean | true | 显示代码编辑器 | | editable | boolean | true | 是否可编辑 | | executorLabel | string | '运行' | 运行按钮文字 | | closeOnOverlayClick | boolean | true | 点击弹窗外部是否关闭 |

Slots

| 插槽名 | 参数 | 说明 | |--------|------|------| | footer | { close } | 底部自定义内容 |

Methods

| 方法 | 说明 | |------|------| | open() | 打开弹窗 | | close() | 关闭弹窗 |

Events

| 事件名 | 参数 | 说明 | |--------|------|------| | close | - | 弹窗关闭 |

依赖

  • vue: ^2.6.0
  • prismjs: ^1.30.0