refactor: page.textarea.vue to use composition api

This commit is contained in:
Norm 2022-07-24 00:50:20 -04:00
parent 2f432dce65
commit cff82ea52e
Signed by untrusted user: norm
GPG key ID: 7123E30E441E80DE

View file

@ -2,38 +2,22 @@
<MkTextarea :model-value="text" readonly></MkTextarea>
</template>
<script lang="ts">
<script lang="ts" setup>
import { watch } from 'vue';
import MkTextarea from '../form/textarea.vue';
import { TextBlock } from '@/scripts/hpml/block';
import { Hpml } from '@/scripts/hpml/evaluator';
import { defineComponent, PropType } from 'vue';
import MkTextarea from '../form/textarea.vue';
export default defineComponent({
components: {
MkTextarea
},
props: {
block: {
type: Object as PropType<TextBlock>,
required: true
},
hpml: {
type: Object as PropType<Hpml>,
required: true
}
},
data() {
return {
text: this.hpml.interpolate(this.block.text),
};
},
watch: {
'hpml.vars': {
handler() {
this.text = this.hpml.interpolate(this.block.text);
},
deep: true
}
}
const props = defineProps<{
block: TextBlock;
hpml: Hpml;
}>();
let text = $ref(props.hpml.interpolate(props.block.text));
watch(props.hpml.vars, () => {
text = props.hpml.interpolate(props.block.text);
}, {
deep: true,
});
</script>