首先,我知道这可能是一个超级简单的问题,但我已经挣扎了一个半小时,我已经完成了。有史以来第一个 vue 项目,所以我从来没有让 2 个组件相互通信,更不用说何时<script setup>涉及了。
任何帮助我理解为什么会这样工作的相关文档都会很棒。我想了解这是如何工作的,但我的谷歌搜索一无所获。
这个应用程序很简单,它只是在某些卡上切换浅色模式和深色模式。它的内容比下面的内容更多,但为了便于阅读,我已经删除了不相关的(工作)代码。
我的App.vue代码:
<script setup>
import {ref, defineProps} from "vue";
import card from './components/card.vue'
const darkMode = ref(false);
const props = defineProps({
darkMode: Boolean
})
</script>
<template>
// Bunch of stuff that is irrelevant to the scope of this problem, it works just fine.
</template>
Run Code Online (Sandbox Code Playgroud)
我的card.vue代码:
<script xmlns="http://www.w3.org/1999/html">
export default {
data() {
return {
}
},
}
</script>
<template>
<h1 :class="{ 'text-white': darkMode }"> Content! </h1>
</template>
Run Code Online (Sandbox Code Playgroud)
这个项目更加复杂,但我现在要做的就是让他们谈谈。darkMode我只想根据是否true …
javascript vue.js vuejs3 vue-composition-api vue-script-setup