- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我对 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/
我在将过滤器从 vue 1 迁移到 vue 2 时遇到问题,我在这里完全创建了我需要的东西(突出显示与输入文本匹配的文本): Vue.component('demo-grid', { templa
我有一个在 vue 组件外部运行的函数。我想要将它返回的数据传递给vue组件中的数据。 function example(){ var item = 'item'
我正在尝试安装一个 Vue 插件,以便我可以使用选项管理一些 API 调用。我有一个 stocks.js 文件,我想从中进行 API 调用。 当我执行以下操作时,出现'Vue is defined b
如何从指令访问 Vue 实例? 我有这个 HTML 和这个脚本 var app = new Vue({ el: '#vueApp', data: { myData:
如何在 .vue 文件中使用 Vue.set() 和 Vue.use()?我正在使用 vue-cli 搭建我的项目,我需要使用 Vue.use(VeeValidate) 进行验证。我也想使用类似下面的
从 vue-property-decorator 和 vue 导入 Vue 之间有什么区别和用例?据我所知,在使用 @Component 装饰器定义自定义组件时,我始终需要从 vue-property
有没有办法使用 yarn serve(可能使用 webpack/vuetify-loader)在本地 Vuetify 应用程序的本地 npm 依赖项上发生热重载? 商业案例 我们有一些通用的 Vuet
我有一个在某些未知情况下不可靠的插槽的奇怪错误。 成分 有3个层次组件。 孙子 (headlessTable),它提供一个名为 arrayValue 的插槽. 子项 (collapsableCard)
我是 Vue 本地新手,我也遇到了一个问题,can I use the Vue component inside a Vue native component such as Vue-chart an
Vue.delete 的替代方案是什么?在 Vue 3 的新 Reactivity API 中? 最佳答案 Vue.delete和 Vue.set在 Vue 3 中不需要。通过使用代理的新 react
我是 Vue 的新手,正在尝试学习如何使用它。 我想我在尝试安装一个新的 Vue 应用程序时被绊倒了。 这是我可以开始工作的内容: const vm = new Vue({}) 从那里我可以安装
我使用boots-vue。我从文档https://bootstrap-vue.js.org/docs/components/table/#table-body-transition-support中举
我真的只是想为我的图书馆建立一个 jest+vue 的框架,并迅速得到这个错误。 我知道这个结构不是通常的笑话结构,我在这里尝试用一个辅助控件来描述一个测试。 这是我的test的内容文件夹:array
我正在尝试使用基于 examples 的 vue-router , 如 let routes = [ { path: '/', component: MainComponent }, ];
我有一个想要通过简单的 v-model 功能发布到 NPM 的组件。 因此,如果它能够在 vuejs 2/3 上互换运行那就更理想了。 我可以通过将组件设置为发出 input 和 update:mod
我正在尝试在 bootstrap-vue 表中创建一个插槽,以使用自定义组件呈现任何 bool 值。 所以我有一个简单的表格 现在,如果我想以特定方式渲染单个列,我必须使用插槽 它有
Vue Router 在主 Vue 实例之前加载,但要加载该 Router,我应该准备一些信息,然后将它们作为属性传递给此 Route。在此示例中,它是从主 Vue 实例传递到主屏幕的 current
我有一个想要通过简单的 v-model 功能发布到 NPM 的组件。 因此,如果它能够在 vuejs 2/3 上互换运行那就更理想了。 我可以通过将组件设置为发出 input 和 update:mod
我找到了一个关于如何使用 Vue 路由器的很好的例子。这是 app.js 文件: // Telling Vue to use the router Vue.use(VueRouter) // Init
我没有完整的 vue 应用程序,所以我使用 custom elements替换一些应该用 vue 处理的元素。 我只想使用 vue multiselect plugin在 html 文件中。 所以我尝
我是一名优秀的程序员,十分优秀!