gpt4 book ai didi

javascript - [Vue 警告] : $attrs is readonly. [Vue 警告]:$listeners 是只读的

转载 作者:搜寻专家 更新时间:2023-10-30 22:13:30 25 4
gpt4 key购买 nike

我对 Vuejs 比较陌生,每次按键时都会收到以下警告:

[Vue warn]: $attrs is readonly.

found in

---> <RouterLink>
<HeaderComponent> at src\components\Header_Component.vue
<App> at src\App.vue
<Root>

[Vue warn]: $listeners is readonly.

found in

---> <RouterLink>
<HeaderComponent> at src\components\Header_Component.vue
<App> at src\App.vue
<Root>

不过,这些警告似乎根本不会影响可用性。我在任何地方都没有调用 $attrs 或 $listeners,我不确定这些警告是从哪里来的。

这是我的 Header_Component.vue:

<template>
<header class="header">
<div class='nav nav-side nav-oneLine'>
<a class='nav-link' href='#'><router-link @click.native="addClass(), setLogoTrue('project')" to='/Projects'>PROJECTS</router-link></a>
<a class='nav-link' href='#'><router-link @click.native="addClass(), setLogoTrue('blog')" to='/Blog'>BLOG</router-link></a>
<a class='nav-link' href='#'><router-link @click.native="addClass(), setLogoTrue('aboutme')" to='/Aboutme'>ABOUT ME</router-link></a>
<a class='nav-link' href='#'><router-link @click.native="addClass(), setLogoTrue('resume')" to='/Resume'>RESUME</router-link></a>
</div>
</header>
</template>

<script lang="ts">
import Vue from 'vue'

export default Vue.extend({
data() {
return{
logoTrue: <Object> {
'main': true,
'project': false,
'blog': false,
'aboutme': false,
'resume': false
},
main: <boolean>true,
header: <any>"",
image: <any>"",
h1: <any>"",
h2: <any>"",
nav: <any>"",
logos: <any>"",
break: <any>"",
}
},
components: {
insta, facebook, github, codepen, mainLogo, mainLogoSmall, test, projectsLogo, blogsLogo, aboutmeLogo, resumeLogo
}
methods:{
addClass(){
if (document.querySelector('.h2Active') == null && document.querySelector('.header_top') == null) {
this.add_newClasses()
this.emit_finished(true)
setTimeout(() => {
this.remove_separators()
}, 800)
} else {
console.log('classes already exist!')
this.$emit('reloadBackToTop')
}
},
remove_separators() {
let breaker = document.getElementsByClassName('separator')

while (breaker[0]) {
this.nav.removeChild(breaker[0])
}
},
setLogoTrue(target) {
for (var key in this.logoTrue) {
if (this.logoTrue.hasOwnProperty(key)) {
if (key == target) {
this.logoTrue[key] = true
} else {
this.logoTrue[key] = false
}
}
}
},
apply_topClasses() {
this.header.classList.add('header_top')
this.image.classList.add('imgStatic_top')
this.h1.classList.add('h1_name_top')
this.h2.classList.add('h2_name_top')
this.logos.classList.add('logo_links_top')
this.nav.classList.add('nav-side_top')

this.emit_finished(false)
},
add_newClasses() {
if (window.innerWidth < 1060) {
this.nav.classList.add('navActive_small')
this.image.classList.add('imgActive_small')
} else {
this.nav.classList.add('navActive')
this.image.classList.add('imgActive')
}
this.logos.classList.add('logo_linksActive')
this.header.classList.add('headerActive')
this.h1.classList.add('h1Active')
this.h2.classList.add('h2Active')

this.image.classList.remove('imgStatic')
},
emit_finished(delay:boolean) {
if (delay) {
setTimeout (() => {
this.$emit('finishedLoading')
console.log('finished_loading')
}, 2000)
} else {
console.log('here')
this.$emit('finishedLoading')
}
},
adjust_clientWidth() {
if (window.innerWidth < 1060) {
// this.remove_separators()
let bigActive = document.getElementsByClassName('big-nav')
let navActive = document.getElementsByClassName('navActive')
if (bigActive.length > 0) {
this.nav.classList.add('small-nav')
this.nav.classList.remove('big-nav')

this.image.classList.add('small-img')
this.image.classList.remove('big-img')

} else if (navActive.length > 0) {
this.nav.classList.add('small-nav')
this.nav.classList.remove('nav-side')
this.nav.classList.remove('navActive')

this.image.classList.add('small-img')
this.image.classList.remove('imgActive')
}
} else {
let smallActive = document.getElementsByClassName('small-nav')
let smallnavActive = document.getElementsByClassName('navActive_small')
if (smallActive.length > 0) {
this.nav.classList.add('big-nav')
this.nav.classList.remove('small-nav')

this.image.classList.add('big-img')
this.image.classList.remove('small-img')

} else if (smallnavActive.length > 0) {
this.nav.classList.add('big-nav')
this.nav.classList.remove('nav-side')
this.nav.classList.remove('navActive_small')

this.image.classList.add('big-img')
this.image.classList.remove('imgActive_small')
}
}
}
},
created: function() {
window.addEventListener('resize',this.adjust_clientWidth)
},
mounted: function() {
this.header = document.getElementsByClassName('header')[0]
this.image = document.getElementsByClassName('img')[0]
this.h1 = document.getElementsByClassName('h1_name')[0]
this.h2 = document.getElementsByClassName('h2_name')[0]
this.nav = document.getElementsByClassName('nav')[0]
this.logos = document.getElementsByClassName('logo_links')[0]

if (window.location.hash != "#/") {
this.remove_separators()
if (window.location.hash == "#/Projects") {
this.setLogoTrue('project')
} else if (window.location.hash.includes("#/Blog") || window.location.hash.includes("#/blog")) {
this.setLogoTrue('blog')
} else if (window.location.hash == "#/Aboutme") {
this.setLogoTrue('aboutme')
} else if (window.location.hash == "#/Resume") {
this.setLogoTrue('resume')
}
this.apply_topClasses()
}
}
})
</script>

<style lang="css" scoped>
(...)
</style>

感谢您的帮助!

最佳答案

您可能已经从另一个问题中了解到,我在这里发布一个答案是为了节省其他人的时间。

此类错误的问题通常是因为您多次导入 Vue。首先在您的主应用程序中,然后也在您的组件文件中。因此,从 Header_Component.vue 中删除 import Vue from 'vue' 行将解决问题。但是您必须将声明组件的方式更改为:

<script lang="ts">
//import Vue from 'vue' <-- Commented the import line

export default { // <-- Removed Vue.extend()
data() {
return{
logoTrue: <Object> {
'main': true,
'project': false,
'blog': false,
'aboutme': false,
'resume': false
},
main: <boolean>true,
header: <any>"",
image: <any>"",
h1: <any>"",
h2: <any>"",
nav: <any>"",
logos: <any>"",
break: <any>"",
}
}
...more code...
}
</script>

Here更多的是关于单个文件组件。

关于javascript - [Vue 警告] : $attrs is readonly. [Vue 警告]:$listeners 是只读的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52213260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com