vue.js - 如何更改另一个组件数据
问题描述
activetab
当我单击组件中的按钮时,我需要更改另一个tabsnavlist
组件。tabsnavlist
工作正常,但我无法理解如何将activetab
数据传输到另一个组件。
<template lang="pug">
nav.card-menu-box(:style="{'min-height': sizeblock+'px'}")
.card-menu-box__wrap
.card-menu-box__float(:class="{'float': floatblock, 'fixed-f': fixedfooter}")
.wrap
button.btn.btn_alt.btn_noactive(:class="{'active': activetab == index}", v-for="item, index in buttons", :data="item", :key="item", @click="activetab = index") {{ item }}
</template>
<script>
export default {
name: "tabsnavlist",
data() {
return {
activetab: 0,
tabint: 0,
floatblock: false,
sizeblock: 0,
getFooterPos: 0,
fixedfooter: false
}
},
props: {
buttons: {
type: Array,
default: function() {return []}
}
},
mounted() {
this.hResize();
this.handleScroll();
},
created: function () {
window.addEventListener('scroll', this.handleScroll);
window.addEventListener('resize', this.hResize);
},
destroyed: function () {
window.removeEventListener('scroll', this.handleScroll);
window.removeEventListener('resize', this.hResize);
},
methods: {
navToFooter() {
if(window.scrollY > document.getElementsByClassName("g__footer")[0].offsetTop - window.innerHeight) {
this.fixedfooter = true
} else {
this.fixedfooter = false
}
},
handleScroll() {
if(this.$el.getBoundingClientRect().top <= 0) {
this.floatblock = true
} else {
this.floatblock = false
}
this.navToFooter();
},
hResize() {
this.navToFooter();
this.sizeblock = parseInt(this.$el.children[0].clientHeight);
}
}
}
</script>
在页面中我有 htmltabblock
是:
productpage
.grid
tabsnavlist(:buttons="[1,2,3]"
.gridst
p there is another html, thats why i cant compare it in one component
.grid
tabblocks
tablock(title="1" :class="{'active': activetab == index}")
p tab 1
tablock(title="2" :class="{'active': activetab == index}")
p tab 2
tablock(title="3" :class="{'active': activetab == index}")
p tab 3
解决方案
您可以为此使用 vuex,https: //vuex.vuejs.org 。
推荐阅读
- roblox - Roblox Lua 中的“R 无法分配给”错误
- python - 为什么for循环中的迭代器是字符串而不是整数?
- python - AttributeError:“NoneType”对象没有属性“_instantiate_plugins”
- python - 使用 matplotlib 在 DataFrame 中按 ID 列生成单独的坐标图
- python - 为什么此代码适用于所有内容,除了退出命令
- json - 从 Django 到 Camunda 的 Json Post
- javascript - 循环生成空列表
- mysql - 设置 lower_case_table_names=0 时如何解决 Can't connect to MySQL server on 'localhost' (10061)?
- php - cURL Paypal Identity API 响应提供商家信息,而不是付款人
- codeigniter - 使用 Codeigniter 将日期输入值从视图传递到控制器