1. 程式人生 > >v-for和v-once的用法

v-for和v-once的用法

<template>
    <div id="app">
        <h1>Hello Vuex</h1>
       <p>{{aaa}}</p>
       <button @click="add">+</button>
       <button @click="sub">-</button>  
       <ul>
           <li v-for="(item,index) in items">
               {
{index}}--{{item.message}} </li> </ul> <p v-once>原始資料:{{aaa}}</p> <p>修改過的資料:{{aaa}}</p> </div> </template> <script> export default { data(){ return{ aaa:2, items:[ {
message:'first'}, {message:'second'} ] } }, methods:{ add:function(){ this.aaa++ }, sub:function(){ this.aaa-- } } } </script>