Vue.js Vue-从Vue文件调用beforeMount方法
问题是“A”文件中的Vue.js Vue-从Vue文件调用beforeMount方法,vue.js,vuejs2,vue-component,vuex,Vue.js,Vuejs2,Vue Component,Vuex,问题是“A”文件中的beforemount()方法没有调用,而是调用了file “B”有着和前端调用相同的方法,似乎组件并没有在父文件中被调用(我也有在父文件中挂载之前的组件(文件B也有) 这是我在两个文件中添加的潜在代码,请查看并让我知道 I am trying to call `beforemount()` method from "A" file , this file is imported in another file which is called on homepage tha
beforemount()
方法没有调用,而是调用了file
“B”有着和前端调用相同的方法,似乎组件并没有在父文件中被调用(我也有在父文件中挂载之前的组件(文件B也有)
这是我在两个文件中添加的潜在代码,请查看并让我知道
I am trying to call `beforemount()` method from "A" file , this file is imported in another file which is called on homepage that is "B".
I am not sure what i am missing here.
文件B
从“one/components/theme/A.vue”导入
导出默认值{
数据(){
返回{
A.
},
组成部分:{
A.
}
}
归档
导出默认值{
名称:‘A’,
安装前(){
console.log('装载前的段')
},
}
您必须在B中的组件范围内声明导入的组件A,然后在B的模板中实际使用该组件A
文件B
从“one/components/theme/A.vue”导入A;
导出默认值{
组件:{A}
}
文件A保持不变您必须在B中的Components
范围内声明导入的组件A,然后在B的模板中实际使用该组件A
文件B
从“one/components/theme/A.vue”导入A;
导出默认值{
组件:{A}
}
文件A保持不变让我们使用其他命名约定来解释这一点,我们有ParentComponent.vue和ChildComponent.vue,其思想是在ParentComponent.vue组件中使用ChildComponent.vue:
File B
<script>
import A from 'one/components/theme/A.vue'
export default {
data () {
return {
A
},
components: {
A
}
}
</script>
FILE A
<template>
<div class="A"/>
</template>
<script>
export default {
name: 'A',
beforeMount () {
console.log('segment beforeMount')
},
}
// ChildComponent.vue
<template>
<div>
<p>I'm the child component</p>
</div>
</template>
<script>
export default {
name: "ChildComponent",
beforeMount () {
console.log('segment beforeMount in child')
},
}
</script>
//ChildComponent.vue
我是孩子
导出默认值{
名称:“子组件”,
安装前(){
console.log('在子级中装入之前的段')
},
}
现在让我们看看父组件:
File B
<script>
import A from 'one/components/theme/A.vue'
export default {
data () {
return {
A
},
components: {
A
}
}
</script>
FILE A
<template>
<div class="A"/>
</template>
<script>
export default {
name: 'A',
beforeMount () {
console.log('segment beforeMount')
},
}
// ChildComponent.vue
<template>
<div>
<p>I'm the child component</p>
</div>
</template>
<script>
export default {
name: "ChildComponent",
beforeMount () {
console.log('segment beforeMount in child')
},
}
</script>
//ParentComponent.vue
我是{{message}}组件
从“./routeToChildComponent/ChildComponent.vue”导入ChildComponent
导出默认值{
名称:“父组件”,
//注册要使用的组件
组成部分:{
子组件
},
数据:()=>({
信息:“家长”
}),
安装前(){
console.log('在父级中装入之前的段')
},
}
这样,ParentComponent就可以访问子组件,并且都运行beforeMount钩子。让我们使用其他命名约定来解释这一点,我们有ParentComponent.vue和ChildComponent.vue,我们的想法是在ParentComponent.vue组件中使用ChildComponent.vue:
File B
<script>
import A from 'one/components/theme/A.vue'
export default {
data () {
return {
A
},
components: {
A
}
}
</script>
FILE A
<template>
<div class="A"/>
</template>
<script>
export default {
name: 'A',
beforeMount () {
console.log('segment beforeMount')
},
}
// ChildComponent.vue
<template>
<div>
<p>I'm the child component</p>
</div>
</template>
<script>
export default {
name: "ChildComponent",
beforeMount () {
console.log('segment beforeMount in child')
},
}
</script>
//ChildComponent.vue
我是孩子
导出默认值{
名称:“子组件”,
安装前(){
console.log('在子级中装入之前的段')
},
}
现在让我们看看父组件:
File B
<script>
import A from 'one/components/theme/A.vue'
export default {
data () {
return {
A
},
components: {
A
}
}
</script>
FILE A
<template>
<div class="A"/>
</template>
<script>
export default {
name: 'A',
beforeMount () {
console.log('segment beforeMount')
},
}
// ChildComponent.vue
<template>
<div>
<p>I'm the child component</p>
</div>
</template>
<script>
export default {
name: "ChildComponent",
beforeMount () {
console.log('segment beforeMount in child')
},
}
</script>
//ParentComponent.vue
我是{{message}}组件
从“./routeToChildComponent/ChildComponent.vue”导入ChildComponent
导出默认值{
名称:“父组件”,
//注册要使用的组件
组成部分:{
子组件
},
数据:()=>({
信息:“家长”
}),
安装前(){
console.log('在父级中装入之前的段')
},
}
这样,ParentComponent就可以访问子组件,并且都运行beforeMount钩子。至少您缺少问题中的代码;)请再次检查问题,更新的问题至少您缺少问题中的代码;)请再次检查问题,更新的问题先生,我已经这样做了,但在文件“A”中装入方法之前未执行组件段
来自何处?您没有导入它。是否要调用文件A的beforeMount
?然后,根据回答说明,您必须在B的组件范围内声明A。在B的模板中调用A。beforeMount同时在“B”和“A”的文件中,也在“B”中是父级,在parenr中的mount被执行之前,但是它没有在文件“A”中执行,而文件“A”是子级。您必须从B的模板中的B的模板调用A````也请从B的data()
函数中删除A。从B的data()函数中删除A,先生,我已经这样做了,但在文件“A”中的mount方法之前未执行组件段
来自何处?您没有导入它。是否要调用文件A的beforeMount
?然后,根据回答说明,您必须在B的组件范围内声明A。在B的模板中调用A。beforeMount同时在“B”和“A”的文件中,也在“B”中是父级,在执行parenr中的mount之前,但是它没有在文件“A”中执行,该文件是子级的。您必须从B的模板中的B的模板调用A```也请从B的data()
函数中删除A。从数据()中删除A函数在B中,我在父文件中也有beforeMount,即在使用代码后,当前执行beforeMount()应该执行两次,这就是我想要再次检查的。在你的代码中,你在B的数据属性中返回A,为什么?我有一些要求,感谢代码和正确的语法,它的正确代码。我在父文件中也有beforeMount,也就是在使用你的代码后当前执行的beforeMount()应该执行两次,这就是我想要再次检查的。在你的代码中,你在B的数据属性中返回A,为什么?我有一些要求,感谢代码和正确的语法,它的正确代码。