Vue用v-bind給標簽屬性賦值 src, href...


給屬性渲染數據不能使用 {{name}} 標記, 請使用 v-bind:屬性名稱=”name”
name是json數據鍵值對中的鍵名, 請配合下面JS代碼片食用

HTML

<div id="sidebar">
    <ul>
        <li v-for="list in lists" v-bind:class="class">
            <img v-bind:src="list.src" />
        </li>
    </ul>
</div>

JS

var app = new Vue({
    el: '#sidebar>ul',
    data:{
    "lists":[
        { src:"icon.png" },
        { src:"icon.png" },
        { src:"icon.png" },
    ],
    class:"active",
    name:"劍齒虎"
    }
});


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM