JSFiddle - React, Tailwind, and code Playground
by ycloud
HTML
<div id="app">
{{title}}
<v-title>{{title}}</v-title>
</div>
JavaScript
Vue.component('v-title', {
created() {
this.updateTitle();
},
beforeUpdate() {
this.updateTitle();
},
methods: {
updateTitle() {
let slots = this.$slots.default;
if (typeof slots === 'undefined' ||
slots.length < 1 ||
typeof slots[0].text !== 'string') return;
let {
text
} = slots[0]
let title = document;
if (text !== title) document.title = text;
}
},
template: '<h1 v-if="false">请输入标题</h1>'
})
new Vue({
created() {
this.title = '更新吧,标题';
},
data: {
title: '标题更新示例'
},
el: '#app'
})