事件处理

基本骨架

子组件

axios

v-if

v-for

路由

设置style

计算属性

动态class

路由跳转

store

nextTick

事件处理:

直接写表达式:

  @click="counter += 1"

   调用方法:

   @click="greet"
@click="greet(index)" 
获取事件对象:
   @click="warn('no', $event)"
事件修饰符:
   @click.stop.prevent="doThat"
按键修饰符:
   @keyup.13="submit"

基本骨架:

<script type="text/ecmascript-6">
import axios from 'axios'
export default {
data(){
return {
useId:''
} },
created(){
..............
},
methods:{
loginReq(){
............
}
},
components: {
XInput
}
}
</script>

子组件:

 父组件:
    声明:import BpmRadio from '@/parts/radio'
    注册;
  使用:
<bpm-radio
:appoRadioOption="appoRadioOption" //传数据
@optionChange="optionChange" //子组件派发事件
> </bpm-radio> 子组件:
接收参数:

  props:{
        appoRadioOption:Array
     }, 
   //默认空数组:
      selectedIds:{
         type: Array,
         default: function () {
                 return []
         }
      },
 
    this.$emit('optionChange',this.appoRadioOption[index]) //派发事件并传参
  参数验证与默认:
    num: {
type: Number,
default: 100
},

axios-post请求:

 axios.post('xxxxxxxxxxx',{
userId:this.useId
}
).then((res)=>{
this.$vux.loading.hide()
if(res.data.state==0){ }else{
this.$vux.alert.show({
title:'提示',
content:res.data.message
})
}
}) 或者:
   axios({
      method:'POST',
      url:'xxxxxxxx',
      data:{
          queryKey:queryKey
      },
      headers:{
        "token": "1531798043804ORANMALLEELL"
      }
  }).then((res)=>{

axios-get请求:

 axios({
method:'Get',
url:'xxxxxxxxxx/oorder/getDtl?orderId='+orderId,
}).then((res)=>{

v-if:

<div class="btnBox" v-if="orderStateNum==2">
</div>
<div v-else>
 <divider>暂无留言</divider>
</div>
  <span v-if="optionVal=='IT类服务'">11111</span>
  <span v-else-if="optionVal=='行政办公类服务'">2222</span>

v-for:

遍历数组:

<div class="orItem" v-for="item in orderInfo" @click="clickItem(item.orderId)">
<div class="orItemHeader vux-1px-b">{{statusTag[item.orderState]}}
</div>
<div class="orItemBody vux-1px-b" v-for="proitem in item.orderList">
<div class="txtBox">
<p class="tit">2222222222</p>
<p>2222222222</p>
<p>2222222222</p>
</div>
</div>
</div> 带index:
   <li class="sliderItem" v-for="(item,index) in recomment">{{index}}.{{item.picUrl}}</li>

遍历对象:

 <li v-for="value in object">
{{ value }}
</li>

&获取键名:

   v-for="(value, key) in object"

&获取索引:

   v-for="(value, key, index) in object"

一定范围的取值:

   <span v-for="n in 10">{{ n }} </span>

&与v-if混合使用:

  <li v-for="todo in todos" v-if="!todo.isComplete">  //v-for优先级更高,v-if作用于每一个for循环
{{ todo }}
</li>

路由方法:

this.$router.push({path:`/order/`+orderId})
this.$router.push({name:'catalogDtl',params:{id:item.Fsinger_id},query:{keyworth:'123lxf'}})
this.$router.push({path:`/page20/${item.Fsinger_id}`})

行间:

@click=“$router.go(-1)”

 

使用计算属性:

动态class:

1. 对象内表达式:

 如下模板:
<div class="static" v-bind:class="{ active: isActive, 'text-danger': hasError }"></div>
如下 data:
data: { isActive: true, hasError: false}
渲染为:
<div class="static active"></div>

:class="{'active':index==serverType,'radioItem':true}"

2.返回字符串的表达式:

3.数组内表达式:

:class="[className, isMsg ? 'weui-icon_msg' : ' ']"

变量和字符串混合:

:class="[
     'el-link',
    type ? `el-link--${type}` : '',
    disabled && 'is-disabled'
]"
 设置style:
 
  对象语法:
 
       
  :style="{ color: activeColor, fontSize: fontSize + 'px' }"  //变量为data中的值
 
 

路由跳转:

声明式:<router-link :to="...">
编程式:router.push(...)
this.$router.push({path: '/coach/' + this.$route.params.id, query: queryData});

目标路由获取query:

      this.$route.query.id

store:

直接获取store:

 this.$store.state.wordId
async await:
   methods:{
async checkBatchOpRight(){
let res = await getLabelUsers('1001') //等一个resolve
...
}
}

  

Promise:
export function getLabelUsers (tagId) {
return new Promise((resolve, reject) => {
.........
resolve({
reqSuccess:true,
userList:res.data.userList
})
.........
})
}

变量与表达式:

为dom元素添加事件:

css中使用背景图片:

    background:url('../../assets/cjbg.png');
 

nextTick:
Vue.$nextTick(function(){
console.log(vm.$el.textContent)
}) watch:
watch:{
receiveForm: {
deep: true, //data中对象的值的变化
handler: function (newVal,oldVal){
this.modify()
}
}
}

  

 

vue常用片段的更多相关文章

  1. Vue常用经典开源项目汇总参考-海量

    Vue常用经典开源项目汇总参考-海量 Vue是什么? Vue.js(读音 /vjuː/, 类似于 view) 是一套构建用户界面的 渐进式框架.与其他重量级框架不同的是,Vue 采用自底向上增量开发的 ...

  2. vue常用

    vue常用的路由的状态管理

  3. 五、vue常用UI组件

    下面简单的总结下vue常用的一些UI 组件,有一些我也没怎么用过,这里先罗列出来,便于自己后面使用的时候查找方便,大家有更好的可以给我推荐哦~ vuex: vux github ui demo:htt ...

  4. (二)Vue常用7个属性

    学习vue我们必须之到它的7个属性,8个 方法,以及7个指令.787原则 el属性 用来指示vue编译器从什么地方开始解析 vue的语法,可以说是一个占位符. data属性 用来组织从view中抽象出 ...

  5. Vue常用语法及命令

    1,Vue常用语法 vue常用语法之变量的定义 // 1,变量相关 // 变量的提升 var username = "雪雪"; var username ; console.log ...

  6. Vue常用的GitHub项目

    Vue常用的GitHub项目(Demo案例) 应用实例 https://github.com/pagekit/pa... pagekit-轻量级的CMS建站系统 https://github.com/ ...

  7. vue常用的修饰符

    v-model修饰符 <template> <div id="demo14"> <p>-----------------模板语法之修饰符---- ...

  8. vue进阶:vs code添加vue代码片段

    如何设置? 选择或创建 配置代码 如何使用? 一.如何设置? 进入vs code主界面-->使用快捷键“ctrl + shift + p”: 如果你是使用Preferences:Configur ...

  9. Vue 常用三种传值方式

    Vue常用的三种传值方式: 父传子 子传父 非父子传值 引用官网一句话:父子组件的关系可以总结为 prop 向下传递,事件向上传递.父组件通过 prop 给子组件下发数据,子组件通过事件给父组件发送消 ...

随机推荐

  1. 2018.7.26 进程和线程的区别 &&你对 Java平台的理解

    进程和线程的区别 1.定义 进程:具有一定独立功能的程序关于某个数据集合上的一次运行活动,进程是系统进行资源分配和调度的一个独立单位. 线程:进程的一个实体,是CPU调度和分派的基本单位,它是比进程更 ...

  2. SecureCRT 设置

  3. numpy+pandas+matplotlib+tushare股票分析

    一.数据导入 安装tushare模块包 pip install tushare http://tushare.org/ tushare是一个财经数据接口包 import numpy as np imp ...

  4. CDH4.5.0下安装lzo

    参考 http://www.cloudera.com/content/cloudera-content/cloudera-docs/Impala/1.0.1/Installing-and-Using- ...

  5. 利用Kettle转储接口数据

    1.     项目背景 1.1.  项目背景 数据接口 API:应用程序接口(Application Program Interface)的简称,是实现计算机软件之间数据通信的工具.同时API也是一种 ...

  6. Linux tmpwatch命令

    Linux tmpwatch命令 作为系统管理员,很多时候需要定期清理一定规则的文件,比如过期的日志,过期的归档,已备份的文件等等. 如果使用一定的匹配规则,找出这些文件,然后再传递给rm命令,其实是 ...

  7. vue2.x结合百度UEditor富文本编辑器

    1.首先下载UEditor源码(https://ueditor.baidu.com/website/),将整个文件放到static文件夹中 2.在src/components文件夹下创建公共组件UEd ...

  8. P3366 最小生成树【模板+Kruscal讲解】

    此题数组大小非常重要 算法过程: 现将全部边按照权值(由小到大)排序. 按顺序(同上)考虑每条边,只要这条边和之前已选择的边不构成圈,就保留这条边,否则放弃这条边. 具体算法 成功选择(n-1)条边后 ...

  9. 【思维题 细节】loj#6042. 「雅礼集训 2017 Day7」跳蚤王国的宰相

    挂于±1的细节…… 题目描述 跳蚤王国爆发了一场动乱,国王在镇压动乱的同时,需要在跳蚤国地方钦定一个人来做宰相. 由于当时形势的复杂性,很多跳蚤都并不想去做一个傀儡宰相,带着宰相的帽子,最后还冒着被打 ...

  10. 【c学习-1】

    #include<stdio.h> int main(){ int a,b,max; printf("请输入两个整数:"); //格式化输出函数 scanf(" ...