[Vuejs]-How to replace a string with another string (vue3 composition API)

1👍

There are two other ways you can achieve this:

  1. Using tenary operation
function toggle() {
    isOpen.value = !isOpen.value
    changeString.value = isOpen.value ? 'Ocultar Filtros' : 'Exibir Filtros'
}
  1. You can also use this tenary operation in computed() property where you compute changeString based on change in isOpen
const changeString = computed(() => isOpen.value ? 'Ocultar Filtros' : 'Exibir Filtros'
)

0👍

It sounds like changeString should set itself based on the value of isOpen

function toggle() {
    isOpen.value = !isOpen.value
    if (isOpen.value) {
       changeString.value = 'Ocultar Filtros'
    } else {
       changeString.value = 'Exibir Filtros'
    }
}

Leave a comment