事件处理

基本骨架

子组件

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. 昂贵的聘礼,(最短路的应用),Poj(1063)

    题目链接:http://poj.org/problem?id=1062 很好的一道中文题. 思路: 把每种替换当做一条边,权重为交易优惠,就是求原点0到物品1的最短路. 这里有限制条件,每个节点还有等 ...

  2. 使用node.js + socket.io + redis实现基本的聊天室场景

    在这篇文章Redis数据库及其基本操作中介绍了Redis及redis-cli的基本操作. 其中的publish-subscribe机制应用比较广泛, 那么接下来使用nodejs来实现该机制. 本文是对 ...

  3. cgi程序报 Premature end of script headers:

    这段时间写了一个CGI,也是为了应付工作,挺简单的一个程序,总是在调用的时候报:Premature end of script headers: 很让人头疼!   在网上找了些资料,按资料 ---- ...

  4. MySQL 主从同步 Slave_IO_Running: No

    MariaDB [chen]> show slave status \G *************************** 1. row ************************* ...

  5. express_webpack自动刷新

    现在,webpack可以说是最流行的模块加载器(module bundler).一方面,它为前端静态资源的组织和管理提供了相对较完善的解决方案,另一方面,它也很大程度上改变了前端开发的工作流程.在应用 ...

  6. IE 8 下小心使用console.log()

    我们很多情况下会使用console.log() 对代码调试.在chrome下和Firefox下都不会有太大问题,但是在最近我在IE8 下调试时使用了console.log(),就出现一些问题.在IE8 ...

  7. Map the Debris -freecodecamp算法题目

    Map the Debris 1.要求 返回一个数组,其内容是把原数组中对应元素的平均海拔转换成其对应的轨道周期. 原数组中会包含格式化的对象内容,像这样 {name: 'name', avgAlt: ...

  8. ubuntu修改IP地址和网关的方法

    一.使用命令设置Ubuntu IP地址 1.修改配置文件blacklist.conf禁用IPV6 sudo vi /etc/modprobe.d/blacklist.conf 表示用vi编辑器(也可以 ...

  9. Eclipse搭建SpringBoot

    第一种方法(不建议) 首先新建Maven工程 勾选第一个按钮,第三个是选择working set ,你可以不选 下一步,配置工程信息,注意打包为jar 打开pom.xml文件,添加spring-boo ...

  10. dts--framework(一)

    dts 大体框架 framework 定义类 定义方法 tests framework调用所需要的函数 ./dpdk/usertools/cpu_layout.py /sys/devices/syst ...