|
@@ -2,19 +2,47 @@
|
|
|
<template>
|
|
|
<!-- template 模板部分内部职能有一个最外层的div -->
|
|
|
<div id="app">
|
|
|
- <img alt="Vue logo" src="./assets/logo.png">
|
|
|
- <HelloWorld msg="Welcome to Your Vue.js App"/>
|
|
|
+ <img alt="Vue logo" src="./assets/logo.png" />
|
|
|
+ <HelloWorld msg="Welcome to Your Vue.js App" />
|
|
|
<!-- 第三步 使用MyPage组件 -->
|
|
|
- <MyPage/>
|
|
|
+ <MyPage />
|
|
|
<div class="page-two">
|
|
|
<!-- 父组件向子组件穿参 在组件上写一个自定义属性名等于你要传递的变量 -->
|
|
|
- <MyPageTwo str="hello" v-bind:val="myName"/>
|
|
|
+ <MyPageTwo str="hello" v-bind:val="myName" />
|
|
|
</div>
|
|
|
<div class="page-three">
|
|
|
<!-- 子组件向父组件传递参数 -->
|
|
|
- <!-- 子组件向父组件传递参数 通过 自定义事件 -->
|
|
|
- <!-- 这里的getVal 是自定义事件的名称 自己起的名字 -->
|
|
|
- <MyPageThree @getVal="conVal"/>
|
|
|
+ <!-- 子组件向父组件传递参数 通过 自定义事件 -->
|
|
|
+ <!-- 这里的getVal 是自定义事件的名称 自己起的名字 -->
|
|
|
+ <MyPageThree @getVal="conVal" />
|
|
|
+
|
|
|
+ <!-- 父组件 给子组件传递一段html代码 -->
|
|
|
+ <div class="page-four">
|
|
|
+ <MyPageFour>
|
|
|
+ <h1>我是父组件传递过来的html代码</h1>
|
|
|
+ <p>我是父组件传递过来的p标签</p>
|
|
|
+ </MyPageFour>
|
|
|
+ </div>
|
|
|
+ <!-- v-slot (具名插槽) 指令 将传递的标签分组 -->
|
|
|
+ <div class="page-five">
|
|
|
+ <MyPageFive>
|
|
|
+ <template v-slot:header> <span>我是页头</span></template>
|
|
|
+ <template v-slot:footer> <span>我是页脚</span></template>
|
|
|
+ </MyPageFive>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- 生命周期函数 -->
|
|
|
+ <div class="page-six" v-if="isShow">
|
|
|
+ <MyPageSix />
|
|
|
+
|
|
|
+ <button @click="hideCom">隐藏组件</button>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- is 指令 切换组件 -->
|
|
|
+ <div class="box">
|
|
|
+ <!-- is 后边写的哪个组件名称 就显示哪个组件 -->
|
|
|
+ <div is="MyPageFive"></div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
@@ -22,25 +50,35 @@
|
|
|
<script>
|
|
|
// import es6新增的模块化管理
|
|
|
// import 可以引入外部的js文件或组件
|
|
|
-import HelloWorld from './components/HelloWorld.vue'
|
|
|
+import HelloWorld from "./components/HelloWorld.vue";
|
|
|
|
|
|
// 第一步 引入MyPage组件
|
|
|
-import MyPage from "./components/MyPage.vue"
|
|
|
+import MyPage from "./components/MyPage.vue";
|
|
|
+
|
|
|
+import MyPageTwo from "./components/MyPageTwo.vue";
|
|
|
+
|
|
|
+import MyPageThree from "./components/MyPageThree.vue";
|
|
|
+
|
|
|
+import MyPageFour from "./components/MyPageFour.vue";
|
|
|
|
|
|
-import MyPageTwo from "./components/MyPageTwo.vue"
|
|
|
+import MyPageFive from "./components/MyPageFive.vue";
|
|
|
|
|
|
-import MyPageThree from "./components/MyPageThree.vue"
|
|
|
+import MyPageSix from "./components/MyPageSix.vue";
|
|
|
// export default 用于导出js文件内容或当前模块的内容
|
|
|
export default {
|
|
|
- name: 'App',
|
|
|
- data(){
|
|
|
- return{
|
|
|
- myName:"app"
|
|
|
- }
|
|
|
+ name: "App",
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ myName: "app",
|
|
|
+ isShow: true,
|
|
|
+ };
|
|
|
},
|
|
|
- methods:{
|
|
|
- conVal(val){
|
|
|
- console.log("父组件接收到子组件传递过来的值",val);
|
|
|
+ methods: {
|
|
|
+ conVal(val) {
|
|
|
+ console.log("父组件接收到子组件传递过来的值", val);
|
|
|
+ },
|
|
|
+ hideCom() {
|
|
|
+ this.isShow = false; // 点击按钮隐藏组件
|
|
|
}
|
|
|
},
|
|
|
components: {
|
|
@@ -48,9 +86,12 @@ export default {
|
|
|
// 第二步 注册MyPage组件
|
|
|
MyPage,
|
|
|
MyPageTwo,
|
|
|
- MyPageThree
|
|
|
- }
|
|
|
-}
|
|
|
+ MyPageThree,
|
|
|
+ MyPageFour,
|
|
|
+ MyPageFive,
|
|
|
+ MyPageSix
|
|
|
+ },
|
|
|
+};
|
|
|
</script>
|
|
|
|
|
|
<style>
|
|
@@ -62,20 +103,54 @@ export default {
|
|
|
color: #2c3e50;
|
|
|
margin-top: 60px;
|
|
|
}
|
|
|
-.page-two{
|
|
|
+.page-two {
|
|
|
position: fixed;
|
|
|
top: 100px;
|
|
|
right: 100px;
|
|
|
width: 400px;
|
|
|
height: 400px;
|
|
|
- border:3px solid black
|
|
|
+ border: 3px solid black;
|
|
|
}
|
|
|
-.page-three{
|
|
|
+.page-three {
|
|
|
position: fixed;
|
|
|
- top:100px;
|
|
|
+ top: 100px;
|
|
|
left: 100px;
|
|
|
width: 400px;
|
|
|
height: 400px;
|
|
|
- border:3px solid black;
|
|
|
+ border: 3px solid black;
|
|
|
+}
|
|
|
+.page-four{
|
|
|
+ position: fixed;
|
|
|
+ bottom: 50px;
|
|
|
+ left: 100px;
|
|
|
+ width: 400px;
|
|
|
+ height: 200px;
|
|
|
+ border: 3px solid black;
|
|
|
+}
|
|
|
+.page-five{
|
|
|
+ position: fixed;
|
|
|
+ bottom: 50px;
|
|
|
+ right: 100px;
|
|
|
+ width: 400px;
|
|
|
+ height: 200px;
|
|
|
+ border: 3px solid black;
|
|
|
+}
|
|
|
+.page-six{
|
|
|
+ position: fixed;
|
|
|
+ width: 200px;
|
|
|
+ height: 200px;
|
|
|
+ border: 3px solid black;
|
|
|
+ bottom: 50px;
|
|
|
+ left: 50%;
|
|
|
+ margin-left: -100px;
|
|
|
+}
|
|
|
+.box{
|
|
|
+ position: fixed;
|
|
|
+ width: 200px;
|
|
|
+ height: 200px;
|
|
|
+ border: 3px solid black;
|
|
|
+ top: 50px;
|
|
|
+ left: 50%;
|
|
|
+ margin-left: -100px;
|
|
|
}
|
|
|
</style>
|