缘由

在使用vue过程中,遇到bug了,怎么去查看到底哪里出了问题呢?

这时候Vue SFC Playground的用处就来了,使用这个playground,可以查看parser、transform、generate后的代码:

例子

在线体验
image.png

  1. <script setup>
  2. import { ref } from 'vue'
  3. const msg = ref('This is Vue SFC Playground!')
  4. </script>
  5. <template>
  6. <h1>{{ msg }}</h1>
  7. <input v-model="msg">
  8. </template>

image.png

  1. /* Analyzed bindings: {
  2. "ref": "setup-const",
  3. "msg": "setup-ref"
  4. } */
  5. import { toDisplayString as _toDisplayString, createElementVNode as _createElementVNode, vModelText as _vModelText, withDirectives as _withDirectives, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
  6. import { ref } from 'vue'
  7. const __sfc__ = {
  8. setup(__props) {
  9. const msg = ref('This is Vue SFC Playground!')
  10. return (_ctx, _cache) => {
  11. return (_openBlock(), _createElementBlock(_Fragment, null, [
  12. _createElementVNode("h1", null, _toDisplayString(msg.value), 1 /* TEXT */),
  13. _withDirectives(_createElementVNode("input", {
  14. "onUpdate:modelValue": _cache[0] || (_cache[0] = $event => ((msg).value = $event))
  15. }, null, 512 /* NEED_PATCH */), [
  16. [_vModelText, msg.value]
  17. ])
  18. ], 64 /* STABLE_FRAGMENT */))
  19. }
  20. }
  21. }
  22. __sfc__.__file = "App.vue"
  23. export default __sfc__

image.png

引用组件

  1. 使用Vue SFC Playground也可以使用组件

image.png

  1. 按回车组件创建完成 按esc取消创建

image.png
在组件中添加一些代码
image.png

  1. 引用组件

image.png