欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

记录vue的一些应用

程序员文章站 2022-07-12 13:34:34
...

1.v-for渲染菜单列表,点击某一项菜单改变颜色

html:

<dl class="filter-price">
  <dt>Price:</dt>
   <dd><a href="javascript:void(0)" @click="setPriceFilter('all')" v-bind:class="{'cur':priceChecked=='all'}">All</a></dd>
   <dd v-for="(price,index) in priceFilter">
     <a href="javascript:void(0)" @click="setPriceFilter(index)" v-bind:class="{'cur':priceChecked==index}">{{price.startPrice}} - {{price.endPrice}}</a>
   </dd>         
 </dl>

js:

data () {
      return {
		priceFilter:[
		    {
		   	 	startPrice:'0.00',
		       	endPrice:'500.00'
		    },
		    {
		     	startPrice:'500.00',
		     	endPrice:'1000.00'
		    },
		    {
		     	startPrice:'1000.00',
		     	endPrice:'2000.00'
		    }
		 ],
		 priceChecked:'all'
	 }
},
methods:{
      setPriceFilter(index){
        this.priceChecked = index;
      }
}

css:

<style>
.cur{
	color:#ee7a23;
	font-weight: bold;
}
</style>

2在vue组件中引用外部样式

<script>
  //引入样式
  import '../assets/css/base.css'
  import '../assets/css/product.css'
  export default {
  
  }
 </script>