题意:将这段JavaScript代码转换为Vue 3的格式
问题背景:
Hi i am trying to add darkmode to my project and im following a tutorial but it seems that its a javascript tutorial instaed of a vue one and this section of code is not working and was wondering if someone could help me in converting it to vue 3. this is the tutorial link if it helps. many thanks
你好,我正在尝试给我的项目添加深色模式,并且我在跟着一个教程学,但看起来它是一个JavaScript教程而不是Vue教程,并且这部分代码不起作用。我想知道是否有人能帮我将它转换为Vue 3的格式。如果提供教程链接有帮助的话,我可以提供。非常感谢!
<button onClick={() > setDarkMode(!darkMode)}>
{darkMode ? (
<SunIcon size="4rem" />
) : (
<MoonIcon size="4rem" />
)}
</button>
问题解决:
i can't see the page you provided, but I will directly convert the code.
我看不到你提供的页面,但我会直接转换代码。
<button @click="darkmode=!darkmode">
<MoonIcon v-if="darkmode" size="4rem" />
<SunIcon v-else size="4rem" />
</button>
if you are using composition api:
如果你正在使用Composition API:
setup(){
const darkmode = ref(false)
return {darkmode}
}
if it's options api:
如果是Options API:
data(){
return {
darkmode: false
}
}

5127




被折叠的 条评论
为什么被折叠?



