您的位置:首页 > 产品设计 > UI/UE

Vue有坑慎入

2016-02-01 17:18 525 查看

vue小总结

正常使用:

<a href="detail.html?id={{ product.id }}" v-for='product in products'>
<div id='pro-title' v-text='product.title'></div>
<div v-if="product.status===1">预热中</div>
<div v-if="product.status===2">众筹中</div>
</a>

//编译的结果:
<a href="detail.html?id=11">
<div id='pro-title'>标题1</div>
<div>预热中</div>
</a>
<a href="detail.html?id=12">
<div id='pro-title'>标题2</div>
<div>众筹中</div>
</a>

//template和if的区别(一个模块需要循环或者遍历的时候,又不想再外层包一个div)
<template v-if="1===1">
<div>abc</div>
<div>dev</div>
</template>
//上面的代码会被编译如下:
<div>abc</div>
<div>dev</div>


使用图片的时候请用以下“:”语法避免vue初始化404:

<img :src="product.imgUrl" class="product-big-img"/>


使用swiper轮播图用一下语法:(:是防止vue初始化404,data-src是swiper做懒加载用的,后面会转化为src)(vue初始化new一定要放在swiper初始化之前)

<img :data-src="banner.bannerPicUrl" class="swiper-lazy"/>
<div class="swiper-lazy-preloader"></div>


vue可以在v-text中直接使用部分函数和部分表达式:

vue可以

<div id="app">
<div v-text="'¥'+message+'元'"></div>
<div v-text="parseFloat(num).toFixed(2)"></div>
<div v-text="bool ?'right':'wrong'"></div>
<div v-text="pic || '/default.png' | addPer host "></div>
</div>

<script>
new Vue({
el: '#app',
data: {
message: 'Hello Vue.js!',
num:3.1234,
bool:false,
pic:'',
host:'http://www.xyz.com'
}
})
</script>
//运行的结果如下:
¥Hello Vue.js!元
3.00
wrong http://www.xyz.com/default.png[/code] 
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  vue