vue 父子元件間互相獲取資料 呼叫方法

2021-10-05 21:09:49 字數 1406 閱讀 8848

一、父元件獲取子元件的資料/呼叫子元件的方法

1、呼叫子元件的時候定義乙個ref

"childfile"

>

<

/logo>

2、在父元件裡面通過

this

.$refs.childfile.屬性

this

.$refs.childfile.方法

二、子元件獲取父元件的資料/呼叫子元件的方法

this

.$parent.資料

this

.$parent.方法

三、示例**

父元件:

="back animation-target" id=

"back"

>

"childfile"

>

<

/logo>

="icon" @click=

"usechildmeth()"

>

<

/div>

<

/div>

<

/template>

import logo from

'../components/logo'

import

from

'vuex'

export

default},

components:

,mounted()

, methods:

,usechildmeth()

,parentmeth()

}}<

/script>

<

!-- add "scoped" attribute to limit css to this component only --

>

@import

'./css/style.css'

;<

/style>

子元件:

="logo" @click=

"getdadmeth()"

>

<

/div>

<

/template>

import

from

'vuex'

export

default},

mounted:

function()

, methods:

,getdadmeth()

,}}<

/script>

vue父子元件間互相傳遞資料

vue父子元件間傳遞引數 1.父傳子 使用 props 向子元件傳遞資料。在父元件中定義 hmsg引數,v bind 繫結childmsg的值為hmsg 子元件使用props獲取父元件傳遞過來的資料 parent.vue parenth2 child1msg hmsg child1 div temp...

Vue父子元件間呼叫

父元件 在父元件中需要引入子元件,並通過 屬性名方式 進行資料繫結 子元件 在子元件中使用prop屬性進行接收資料,定義props屬性就無需在data中定義 export default methods props list 子元件 定義乙個方法,this.datalist 就是要傳遞的資料 met...

Vue 父子元件間的通訊

前言在 vue 專案中父子元件的通訊是非常常見的,最近做專案的時候發現對這方面的知識還不怎麼熟練,在這邊做一下筆記,系統學習一下吧。父元件傳值給子元件,這個就比較常見了,直接用 props 就可以了。但是就算是 props 子元件那邊也有三種寫法,如下面 所示 父元件 子元件 1 簡單粗暴就給個名稱...