• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    해결됨

vue3 강의 중에서..... const에다가 ref()를 쓰면은???

21.04.16 17:06 작성 조회수 816

1

아래와 코드에서 const showProfileDropdown = ref(false)이 친구는 값이 바뀌는 친구 인데 const를 쓴 이유가 궁금합니다.

혹시 ref와 연관이 있을까요?

export default {
  setup() {
    const routes = ref([])
    const showProfileDropdown = ref(false)
    const currentUser = computed(()=>store.state.user)

    onBeforeMount(()=>{
      routes.value = router.options.routes
    })
    const onLogout = async ()=> {
      await auth.signOut()
      store.commit("SET_USER",null);
      await router.replace("/login");
    }
    return {
      routes,
      showProfileDropdown,
      onLogout,
      currentUser,
    }
  }
}

답변 1

답변을 작성해보세요.

1

일반적인 상식선에서 생각하시면 의문이 생기실 수도 있겠네요.

const 의 경우 배열이나 객체의 값은 변경 가능합니다.

ref 지정할때 특별한 경우를 제외하고는 const로 하시면 됩니다.

한승훈님의 프로필

한승훈

질문자

2021.04.16

넵 그냥 ref로 지정할때는 싹다 const로 쓰겟습니다 문제가 안된다면

네 크게 신경쓰지 않으셔도 됩니다.