我有一个父组件(Vue)和子组件 .
我有几个通过改变当前数据在组件之间切换的元素 .
问题是我不知道如何标记活动标签 .
我做了很多事情,在更新的,更新的,已安装的,创建的,在之前创建的生命挂钩之间切换 . 但没有任何效果 .
此代码仅适用于初始加载(即“Home”),我希望它只能设置活动的样式,而不是其他任何内容 . 但它没有悲伤地工作 .
大多数情况下,它既可以工作但可以对所有访问过的链接进行样式处理,或者根本不起作用或在初始活动选项卡上工作(如此)
父组件的重要代码部分:
Copyright © All Rights Reserved
import Home from "./components/Home.vue";
import Aboutus from "./components/About us.vue";
import Contact from "./components/Contact.vue";
import Reservation from "./components/Reservation.vue";
import Signup from "./components/Signup.vue";
export default {
components: {
Home: Home,
"About-us": Aboutus,
Contact: Contact,
Reservation: Reservation,
Signup: Signup
},
data() {
return {
navbar: {
Home: "Home",
Reservation: "Reservation",
About: "About us",
Contact: "Contact"
},
current: "Home"
};
},
mounted: function() {
let actie = document.querySelector("." + this.current);
actie.className = "active";
},
beforeUpdate: function() {
let actie = document.querySelector("." + this.current);
actie.className = "none";
},
methods: {}
};