var app = new Vue({ el: "#app", data: { item: { header: "這裡是 header", title: "這裡是 title", text: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Enim perferendis illo reprehenderit ex natus earum explicabo modi voluptas cupiditate aperiam, quasi quisquam mollitia velit ut odio vitae atque incidunt minus?", }, current: "primary-component", //主要使用的屬性 }, });
只要在 HTML 標籤的局部物件中加上 is="current" 這個屬性資料,就可以靜態完成新增此元件的功能,很簡單吧!
var app = new Vue({ el: "#app", data: { item: { header: "這裡是 header", title: "這裡是 title", text: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Enim perferendis illo reprehenderit ex natus earum explicabo modi voluptas cupiditate aperiam, quasi quisquam mollitia velit ut odio vitae atque incidunt minus?", }, current: "primary-component", }, });
改寫 HTML
在動態切換元件有看到 ul 清單列表內有兩個 a 連結,其中有綁定 click 事件,當點擊時,透過 v-bind:class 新增 active 屬性,並切換背景色。