vuejs組件內(nèi)的props的屬性賦值問題?
問題描述
組件:<test :loading.sync="loading"></test>
Vue.component('test',{ template: '#testText', props: { loading: { type: Boolean, default: false} }, methods: {getData: function (data) { this.loading = false;//此句有錯(cuò)誤,該如何更正} }});new Vue({el: '#indexBox',data: { loading : false},methods : {loadMore: function () { this.loading = true;} } });
我想在子組件里面變更loading的值回傳給父組件,請(qǐng)問該如何控制loading
問題解答
回答1:你用的是vue2吧,如果是vue2的話就應(yīng)該用事件來把子組件的狀態(tài)傳給父組件,有兩種辦法,一種是在父組件中傳一個(gè)v-model='outerLoading',然后子組件里面
watch:{ outerLoading (v) {this.innerLoading = v }, innerLoading (v) {this.emit('input', v) }}
這樣outLoading就會(huì)響應(yīng)innerLoading,實(shí)現(xiàn)雙向綁定的功能。還有一種做法和這個(gè)類似,就是把this.emit('input', v)換成this.emit('eventName', v),然后在父組件中@eventName='eventFunc', 再通過父組件中的eventFunc(v) { //code... }來響應(yīng)子組件的狀態(tài)
相關(guān)文章:
1. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””2. docker - 如何修改運(yùn)行中容器的配置3. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題4. docker鏡像push報(bào)錯(cuò)5. 前端 - @media query 使用出現(xiàn)的問題?6. 利用IPMI遠(yuǎn)程安裝centos報(bào)錯(cuò)!7. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯(cuò)誤?8. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????9. phpstudy8.1沒集成mysql-front10. html - css氣泡,實(shí)現(xiàn)“倒三角(不知道算不算三角了)”可透明的。

網(wǎng)公網(wǎng)安備