项目报错:Assignment to constant variable.

项目报错:Assignment to constant variable._第1张图片

<script setup>
import { ref, computed, reactive } from 'vue';

defineProps({
	msg: String
});

const count = ref(0);
const count1 = reactive(1);
console.log(count, 'count');

const computedValue = computed(() => {
	return count1++;
});
console.log(computedValue, 'computedValue');
</script>
const一般是声明常量,如const a=1,const声明的变量不得改变值,这意味着,const一旦声明变量,就必须立即初始化,不能留到以后赋值。

原因:const问题报错 常量不可修改其值

const computedValue = computed(() => {
return count1 > 0 ? ‘2’ : ‘3’;
});

你可能感兴趣的:(JavaScript,javascript)