美文网首页
vue中正确的语法格式

vue中正确的语法格式

作者: guoss | 来源:发表于2018-06-26 10:55 被阅读0次

.vue中字符串模板文件

<template></template>
<script></script>
<style lang="stylus" scoped></style>//使用stylus的语法格式 scoped表示只在当前内部使用

script中钩子及属性的使用语法

import BScroll from 'better-scroll'; //引入文件 
export default{
  name:'CityList',
  data(){
    return {
      datat:{}
    }
  },//自定义的值使用时需要加上this的指向
  props:{
    hot:Array,
    cities:Array
  }, //从父组件中获取的值
  computed:{
    json:function(){
      let jsont={}
      let allCityList=this.cities
      let arr=[]
      for(var i=0;i<allCityList.length;i++){
        if(arr.indexOf(allCityList[i].sortLetters)==-1){
          arr.push(allCityList[i].sortLetters)
        }
      }
      for(var j=0;j<arr.length;j++){
        let key=arr[j]
        jsont[key]=[]
        for(var xx=0;xx<allCityList.length;xx++){
          if(key==allCityList[xx].sortLetters){
            jsont[key].push(allCityList[xx])
          }
        }
      }
      return jsont
    }   
  },//通过计算属性获取值,获取速度比computed更快,刷新页面数据也不会丢失
  mounted(){
    this.scroll=new BScroll(this.$refs.wrapperList,{
      click:true
    })
   }//dom元素加载完成执行的操作

在template中即可使用上述操作结果

<div class="area" v-for="(item,key) of json"> //遍历json的返回结果
  <div class="title border-topbottom">{{key.toUpperCase()}}</div>
  <div class="item-list">
    <div class="item border-bottom" v-for="innerItem of item" :key="innerItem.id">      
     {{innerItem.name}}
    </div>
  </div>
</div>

在style样式文件中

@import "~styles/varibles.styl"//样式文件的引入
.list
 position:absolute
 top:1.58rem
 .title
  line-height:.4rem
  background:#eee
 .border-topbottom
  &:before
  background:#ccc
  &:after
  background:#ccc
 .button-list
   padding:.1rem
-------------------------------------------------------------------
对于修改非组件中的样式,可以采用样式穿透的方法
.wrapper >>>.swiper-pagination-bullet-active
  background:#fff !important

相关文章

  • vue中正确的语法格式

    .vue中字符串模板文件 script中钩子及属性的使用语法 在template中即可使用上述操作结果 在styl...

  • Vue.js 起步

    每个Vue应用都需要通过实例化Vue实现。语法格式如下: 接下来让我们通过实例来看下Vue构造器中需要哪些内容:实...

  • vue 中的@、@/和./的区别

    @:表示vue语法中v-on的简写;绑定事件的专用格式。当事件触发的时候,函数才会来调用。 使用格式,在标签内部添...

  • Vue.js起步

    Vue.js 起步 每个 Vue 应用都需要通过实例化 Vue 来实现。 语法格式如下: var app = ne...

  • 02.Vue入门之组件(一)

    1.全局组件 vue注册一个全局组件语法格式如下:Vue.component(tagName, options)t...

  • 写vue比较常犯的错误

    一般初学vue的同学可能会犯下面这类错误。 上面script中的语法错误,正确的语法是下面这样。 以上两种方式都是...

  • Vue.js起步

    每个 Vue 应用都需要通过实例化 Vue 来实现。 语法格式如下: 实例 可以看到在 Vue 构造器中有一个el...

  • vue之computed

    computed的写法 在vue2x中,computed option语法有2种格式。一种是函数写法,一种是对戏那...

  • Dart 控制语句

    if 语句 Dart 中 if 语句与 C 语言的语法格式相同,条件使用 () 括起来。语法格式如下: for 语...

  • [转] webpack解惑:require的五种用法

    webpack中可以写commonjs格式的require同步语法,可以写AMD格式的require回调语法,还有...

网友评论

      本文标题:vue中正确的语法格式

      本文链接:https://www.haomeiwen.com/subject/yqepyftx.html