gpt4 book ai didi

javascript - 我如何在 vue 模板中使用 const?

转载 作者:可可西里 更新时间:2023-11-01 01:47:07 25 4
gpt4 key购买 nike

我试图在 *.vue 文件中定义一个 const:

<script>
export const CREATE_ACTION = 1,
export const UPDATE_ACTION = 2
<script>

并在模板中使用它们:

<template>
...
<select :disabled="mode === UPDATE_ACTION">
....
</template>

但它不起作用。如何在 Vue 模板中使用 const

最佳答案

如果你将它们暴露在你的数据上,你就会使它们成为不必要的 react ,正如@mix3d 提到的......

更好的方法是将它们添加到 Vue 对象中 Reactivity in Depth :

<template>
<div v-if="action === CREATE_ACTION">Something</div>
</template>

<script>
export default {
created() {
this.CREATE_ACTION = CREATE_ACTION;
this.UPDATE_ACTION = UPDATE_ACTION;
}
})
</script>

关于javascript - 我如何在 vue 模板中使用 const?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42662144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com