Writing method 1: use toRef
first import
import {
ref, toRef,reactive} from 'vue';
then declare the variable
const state = reactive({
opacity: 1
})
const opacityRef = toRef(state, 'opacity');
and then assign the variable
opacityRef.value = 0.6;
style
Used in , the use of two v-bind
-way binding data
v-bind
instructions is mainly used for responsive updating of html attributes
.img {
opacity: v-bind(opacityRef);
}
Writing method 2: use toRefs
first import
import {
ref, toRefs,reactive} from 'vue';
then declare the variable
const state = reactive({
opacityRef: 1
})
const {
opacityRef } = toRefs(state);
and then assign the variable
opacityRef.value = 0.6;
Used in style
, use v-bind
two-way binding data (note: to be used in style lang="scss"
)
v-bind
instructions are mainly used for responsive update html attributes
.img {
opacity: v-bind(opacityRef);
}