【问题标题】:Unable to render value of a root-level variable inside of script setup with Vue3无法使用 Vue3 在脚本设置中呈现根级变量的值
【发布时间】:2022-08-18 03:06:31
【问题描述】:

也许codesandbox.io 不支持<script setup>,或者我误解了如何渲染一个简单的变量值。渲染的是msg is,而不是msg is hello world。我错过了什么?

现场示例:https://codesandbox.io/s/winter-surf-f79ohv?file=/src/components/HelloW.vue

这是我的HelloW.vue 组件:

<template>msg is {{ msg }}</template>

<script setup>
const msg = \"hello world\";
</script>

标签: vuejs3


【解决方案1】:

下面是来自 CodeSandBox 的 App.vue 组件的内容。请注意,它正在创建一个Select2 组件并从"./components/Select2.vue" 导入,但您的组件文件名为HelloW.vue。因此,只需将导入文件重命名为 "./components/HelloW.vue",您的 CodeSandBox 就可以工作了。在这种情况下,CodeSandBox 和 Vue.js 没有任何问题。

<template>
  <Select2 />
</template>

<script>
import Select2 from "./components/Select2.vue";
export default {
  name: "App",
  components: {
    Select2,
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-22
    • 2011-01-28
    • 1970-01-01
    • 1970-01-01
    • 2023-01-09
    • 1970-01-01
    相关资源
    最近更新 更多