<h1 class="title">{{ title }}</h1>
{{ title }} -> 是插值表达式
https://github.com/janl/mustache.js
npm install mustache --save
import Mustache from 'mustache';
var data = {
title: 'This is my TITLE for MUSTACHE'
};
var html = Mustache.render(
'<h1 class="title">{{ title }}</h1>',
data
);
document.getElementById('app').innerHTML = html;
const App = {
data() {
return {
title: 'This is my TITLE for MUSTACHE',
author: 'Lance',
dateTime: new Date(),
content: 'This is my CONTENT',
}
},
template: `
<div>
<h1 class="title">{{ title }}</h1>
<p>
<span class="author">{{ author }}</span> - {{ dateTime }}
</p>
<p v-bind:title="content">{{ content }}</p>
</div>
`
}
Vue.createApp(App).mount('#app');
import { h } from 'vue';
const App = {
data() {
return {
title: 'This is my TITLE for MUSTACHE',
author: 'Lance',
dateTime: new Date(),
content: 'This is my CONTENT',
}
},
// template: `
// <div>
// <h1 class="title">{{ title }}</h1>
// <p>
// <span class="author">{{ author }}</span> - {{ dateTime }}
// </p>
// <p v-bind:title="content">{{ content }}</p>
// </div>
// `,
render() {
// h函数参数:
// 1. 目标标签,2. 属性集合 3. 子元素
return h(
'div',
{},
[
h(
'h1',
{
class: 'title'
},
this.title
),
h(
'p',
{},
[
h(
'span',
{
class: 'author',
},
this.author
),
` - ${this.dateTime}`
]
),
h(
'p',
{
title: this.title
},
this.content
)
]
)
}
}
Vue.createApp(App).mount('#app');