|
@@ -6,6 +6,16 @@
|
|
|
<HelloWorld msg="Welcome to Your Vue.js App"/>
|
|
|
<!-- 第三步 使用MyPage组件 -->
|
|
|
<MyPage/>
|
|
|
+ <div class="page-two">
|
|
|
+ <!-- 父组件向子组件穿参 在组件上写一个自定义属性名等于你要传递的变量 -->
|
|
|
+ <MyPageTwo str="hello" v-bind:val="myName"/>
|
|
|
+ </div>
|
|
|
+ <div class="page-three">
|
|
|
+ <!-- 子组件向父组件传递参数 -->
|
|
|
+ <!-- 子组件向父组件传递参数 通过 自定义事件 -->
|
|
|
+ <!-- 这里的getVal 是自定义事件的名称 自己起的名字 -->
|
|
|
+ <MyPageThree @getVal="conVal"/>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -16,13 +26,29 @@ import HelloWorld from './components/HelloWorld.vue'
|
|
|
|
|
|
// 第一步 引入MyPage组件
|
|
|
import MyPage from "./components/MyPage.vue"
|
|
|
+
|
|
|
+import MyPageTwo from "./components/MyPageTwo.vue"
|
|
|
+
|
|
|
+import MyPageThree from "./components/MyPageThree.vue"
|
|
|
// export default 用于导出js文件内容或当前模块的内容
|
|
|
export default {
|
|
|
name: 'App',
|
|
|
+ data(){
|
|
|
+ return{
|
|
|
+ myName:"app"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods:{
|
|
|
+ conVal(val){
|
|
|
+ console.log("父组件接收到子组件传递过来的值",val);
|
|
|
+ }
|
|
|
+ },
|
|
|
components: {
|
|
|
HelloWorld,
|
|
|
// 第二步 注册MyPage组件
|
|
|
- MyPage
|
|
|
+ MyPage,
|
|
|
+ MyPageTwo,
|
|
|
+ MyPageThree
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
@@ -36,4 +62,20 @@ export default {
|
|
|
color: #2c3e50;
|
|
|
margin-top: 60px;
|
|
|
}
|
|
|
+.page-two{
|
|
|
+ position: fixed;
|
|
|
+ top: 100px;
|
|
|
+ right: 100px;
|
|
|
+ width: 400px;
|
|
|
+ height: 400px;
|
|
|
+ border:3px solid black
|
|
|
+}
|
|
|
+.page-three{
|
|
|
+ position: fixed;
|
|
|
+ top:100px;
|
|
|
+ left: 100px;
|
|
|
+ width: 400px;
|
|
|
+ height: 400px;
|
|
|
+ border:3px solid black;
|
|
|
+}
|
|
|
</style>
|