123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <!-- html 模板 html代码部分-->
- <template>
- <!-- template 模板部分内部职能有一个最外层的div -->
- <div id="app">
- <img alt="Vue logo" src="./assets/logo.png">
- <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>
- <script>
- // import es6新增的模块化管理
- // import 可以引入外部的js文件或组件
- 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,
- MyPageTwo,
- MyPageThree
- }
- }
- </script>
- <style>
- #app {
- font-family: Avenir, Helvetica, Arial, sans-serif;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
- text-align: center;
- 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>
|