App.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <!-- html 模板 html代码部分-->
  2. <template>
  3. <!-- template 模板部分内部职能有一个最外层的div -->
  4. <div id="app">
  5. <img alt="Vue logo" src="./assets/logo.png">
  6. <HelloWorld msg="Welcome to Your Vue.js App"/>
  7. <!-- 第三步 使用MyPage组件 -->
  8. <MyPage/>
  9. <div class="page-two">
  10. <!-- 父组件向子组件穿参 在组件上写一个自定义属性名等于你要传递的变量 -->
  11. <MyPageTwo str="hello" v-bind:val="myName"/>
  12. </div>
  13. <div class="page-three">
  14. <!-- 子组件向父组件传递参数 -->
  15. <!-- 子组件向父组件传递参数 通过 自定义事件 -->
  16. <!-- 这里的getVal 是自定义事件的名称 自己起的名字 -->
  17. <MyPageThree @getVal="conVal"/>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. // import es6新增的模块化管理
  23. // import 可以引入外部的js文件或组件
  24. import HelloWorld from './components/HelloWorld.vue'
  25. // 第一步 引入MyPage组件
  26. import MyPage from "./components/MyPage.vue"
  27. import MyPageTwo from "./components/MyPageTwo.vue"
  28. import MyPageThree from "./components/MyPageThree.vue"
  29. // export default 用于导出js文件内容或当前模块的内容
  30. export default {
  31. name: 'App',
  32. data(){
  33. return{
  34. myName:"app"
  35. }
  36. },
  37. methods:{
  38. conVal(val){
  39. console.log("父组件接收到子组件传递过来的值",val);
  40. }
  41. },
  42. components: {
  43. HelloWorld,
  44. // 第二步 注册MyPage组件
  45. MyPage,
  46. MyPageTwo,
  47. MyPageThree
  48. }
  49. }
  50. </script>
  51. <style>
  52. #app {
  53. font-family: Avenir, Helvetica, Arial, sans-serif;
  54. -webkit-font-smoothing: antialiased;
  55. -moz-osx-font-smoothing: grayscale;
  56. text-align: center;
  57. color: #2c3e50;
  58. margin-top: 60px;
  59. }
  60. .page-two{
  61. position: fixed;
  62. top: 100px;
  63. right: 100px;
  64. width: 400px;
  65. height: 400px;
  66. border:3px solid black
  67. }
  68. .page-three{
  69. position: fixed;
  70. top:100px;
  71. left: 100px;
  72. width: 400px;
  73. height: 400px;
  74. border:3px solid black;
  75. }
  76. </style>