关于vue组件传值和事件绑定问题
<template>
<view style="width: 100%; height: 100%;">
<view class="tabs">
<view v-for="(tab, index) in tabs" :key="index" class="tab-item" :class="current==index&&'active'" @click="change(index)">
{{tab.title}}
</view>
</view>
<view class="swiper-box" v-for="(item ,index) in tabs" :key="index">
<!-- #ifdef MP -->
<slot name="{{'content' + index}}"></slot>
<!-- #endif -->
<!-- #ifndef MP -->
<slot :name="'content'+index"></slot>
<!-- #endif -->
</view>
</view>
</template> <script>
export default {
name: 'swiperTab',
props: {
currentTab: {
type: Number,
default: 0
},
tabs: {
type: Array,
default: Array
}
},
data() {
return {
current: this.currentTab
};
},
methods: {
change(e) {
this.current = e;
this.$emit('change', e);
},
scrolltolower(e) {
this.$emit('onReachBottom', this.current);
console.log(this.current)
}
}
}
</script>
<aloys-tab :tabs="tabs" @change="onTabChange">
</aloys-tab>
onTabChange(e) {
this.index = e
},
1.this.$emit('change', e); $emit 可以自定义一个事件,当组件执行这个事件的时候,可以绑定一个自定义事件给使用者
2.e为事件传参,这样可以在使用者执行事件的时候拿到这个参数值
关于vue组件传值和事件绑定问题的更多相关文章
- vue 基础重要组件 模板指令 事件绑定
组件:data methods watch new vue({ data:{ a:1, b:[] }, methods:{ dosomething:function(){ this.a++; } }, ...
- Vue一个案例引发的动态组件与全局事件绑定总结
最近在自学 Vue 也了解了一些基本用法,也记录了一些笔记有兴趣的朋友可以去查看我的其他文章,技术这东西真的不能光靠看,看是没有的,你必须要动手实践,只有在实战项目中才能发现问题,才能发现我们没有掌握 ...
- Vue—组件传值及vuex的使用
一.父子组件之间的传值 1.父组件向子组件传值: 子组件在props中创建一个属性,用以接收父组件传来的值 父组件中注册子组件 在子组件标签中添加子组件props中创建的属性 把需要传给子组件的值赋给 ...
- vue组件传值
组件的传值(组件之间的通讯) 1.父子通信 1)父传子 传递:当子组件在父组件中当做标签使用的时候,通过给子组件绑定一个自定义属性,值为需要传递的数据 接收:在子组件内部通过props进行接收 接收的 ...
- vue ---- 组件传值之间使用 v-model
父子组件通信,都是单项的,很多时候需要双向通信.方法如下: 1.父组件使用:msg.sync="aa" 子组件使用$emit('update:msg', 'msg改变后的值xxx ...
- Vue 组件 传值
注意 Vue模板只能有一个对象,要想用多个对象时用div包裹 一.父组件->子组件 通过props 1.子组件: 声明:proprs =[‘xx’],xx是在父组件中引用子组件,子组件的属性(t ...
- vue.js的一些事件绑定和表单数据双向绑定
知识点: v-on:相当于: 例如:v-on:click==@click ,menthods事件绑定 v-on修饰符可以指定键盘事件 v-model进行表单数据的双向绑定 <template&g ...
- vue样式操作与事件绑定
Vue笔记 1 Vue实例 (VM) var vm = new Vue({ el:'#app', //挂载元素 //数据 data: { title:'值', ...
- Vue组件传值,父传子,子传父,非父子组件
vue3中传值方式: 1.父组件向子组件传值 父组件Blog.vue <template> <div id="blog"> <Alert v-if=& ...
- vue组件传值 part2
非父子组件传值 轻量级 视图层框架 复杂组件间传值,引进其他的工具或者设计模式 1.vuex 2.总线机制 //main line 1.在main.js中注册全局的bus Vue.prototype. ...
随机推荐
- vue项目封装 axios 和 api
一,utils文件夹下新建一个request.js文件 import axios from 'axios'; import QS from 'qs'; import { Toast } from 'v ...
- HTML笨方法仿写站酷
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 20 张图带你全面了解 HTTPS 协议,再也不怕面试问到了!
本文详细介绍了 HTTPS 相较于 HTTP 更安全的原因,包括对称加密.非对称加密.完整性摘要.数字证书以及 SSL/TLS 握手等内容,图文并茂.理论与实战结合.建议收藏! 1. 不安全的 HTT ...
- flutter 2.x运行flutter run 报错Cannot run with sound null safety, because the following dependenciesdon'
flutter 2.x运行flutter run 报错Cannot run with sound null safety, because the following dependenciesdon' ...
- python开发简单的命令行工具
介绍 Python模块argparse,这是一个命令行选项,参数和子命令的解释器,使用该模块可以编写友好的命令行工具,在程序中定义好需要的参数,argparse将弄清楚如何解析 sys.argv中的参 ...
- java画海报
package demotest; import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Font; impor ...
- Grafana 系列文章(十四):Helm 安装Loki
前言 写或者翻译这么多篇 Loki 相关的文章了, 发现还没写怎么安装 现在开始介绍如何使用 Helm 安装 Loki. 前提 有 Helm, 并且添加 Grafana 的官方源: helm repo ...
- 学习ASP.NET Core Blazor编程系列二十五——登录(4)
学习ASP.NET Core Blazor编程系列文章之目录 学习ASP.NET Core Blazor编程系列一--综述 学习ASP.NET Core Blazor编程系列二--第一个Blazor应 ...
- v-html渲染页面的时候 css样式无效
感谢: https://www.cnblogs.com/niuxiaoxian/p/9443873.html 当我们用v-html渲染页面的时候会发现样式并没有添加上,如下 复制代码 <temp ...
- 力扣---1148. 文章浏览 I
Views 表:+---------------+---------+| Column Name | Type |+---------------+---------+| article_i ...