vue组件传值上 2021-07-09 FE Vue vue组件传值上 父传子(props) 12345678910111213Farther.vue <Son :monery="moneryFarther"></Son> Son.vue // 推荐 props:{ monery:{ type:Number, default: 0 } } // 或者 props:{monery} 子传父(通过事件回调机制,父监听子事件,子emit父监听的事件) 1234567891011Farther.vue <Son @play="changePlay"></Son> changePlay(reason){ console.log('家庭作业写完了?不写完不准出去玩') }Son.vue <div @click="wantPlay"></div> wantPlay(){ this.$emit('play','我想出去玩') } vuex/mobx 详解见vuejs官网 localStorage 123456// setlocalStorage.setItem('name','小明')// get localStorage.getItem('name') // '小明'// clear 清空所有localStorage.clear() 事件总线 123456781.挂载在全局原型上Vue.prototype.$bus = new Vue();2.监听事件this.$bus.$on("customEvent", data => { console.log(data);});3.触发事件this.$bus.$emit("customEvent", "触发了事件总线"); 面试 vue组件传值下