vue computed style code example
Example 1: vue conditional class
<div :class="{ 'prop-name': boolVar }"></div>
Example 2: js computed style
window.getComputedStyle(document.getElementById("11")).width
Example 3: vue inline style bind
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
Example 4: computed vue typescript
<template>
<div>
<input type="text" name="Test Value" id="" v-model="text">
<label>{{label}}</label>
</div>
</template>
<script lang="ts">
import { Component, Vue, Watch } from "vue-property-decorator";
@Component({})
export default class About extends Vue {
private text = "test";
get label() {
return this.text;
}
}
</script>
<script lang="ts">
import { defineComponent, ref, computed } from "@vue/composition-api";
export default defineComponent({
setup() {
const text = ref("test");
const label = computed(() => {
return text.value;
});
return {
text,
label
};
}
});
</script>