引入Vue.js ,通過script形式,vue官網語法記錄
創建vue應用,數據和 DOM 已經被建立了關聯,所有東西都是響應式的
1:插值
缺點:讓你的網速慢,或者數據加載失敗時,會在瀏覽器中直接渲染插值【js禁用,javascript報錯也會導致這個問題】
html:
<section id="content">
<p id="Mustache">沒有v-once, {{msg}}</p>
</section>
js:
1 var vm = new Vue({ 2 el:"#content", 3 data: { 4 msg: "hello my lord"
6 } 7 });
result:
2:v-once:通過使用 v-once 指令,執行一次性的插值【當數據改變時,插值處的內容不會繼續更新】
html:
1 <section id="content">
2 插值: 3 <p id="Mustache">{{msg}}</p>
4 <p>v-once:當數據改變時,插值處的內容不會更新</p>
5 <span v-once>{{msg}}</span>
6 </section>
js:
1 var vm = new Vue({ 2 el:"#content", 3 data: { 4 msg: "hello once"
5 } 6 });
result:
3、v-text和v-html
html:
1 <section id="content">
2 v-text: 3 <span v-text="tipHtml"></span><br>
4 原始 HTML:v-html指令 5 <span v-html="tipHtml"></span>
6 </section>
js:
var vm = new Vue({ el:"#content", data: { tipHtml: "<b>小心點,明天</b>" } });
結果:
總結:v-text:會把html標簽也解析為文本,而v-html可以解析html標簽。