e 1 yıl önce
ebeveyn
işleme
3d0b196678

+ 1 - 0
vue2.0/vue初阶/16.事件绑定.html

@@ -42,6 +42,7 @@
                 阻止默认事件 .prevent
                 触发一次     .once
                 触发自身     .self
+                ...
             键盘事件:
                 keydown keyup
          -->

+ 13 - 0
vue2.0/vue高阶/1.归纳.md

@@ -0,0 +1,13 @@
+## 1.引用组件时 需要在vue.config.js中关闭eslint校验 当vue.config.js发生更改 需要重启项目
+## 2.组件的引用方法
+* 1.组件写在components文件夹下 首字母大写 采用驼峰命名法
+* 2.先通过import去引用组件 
+* 3.在components下注册组件名称
+* 4.在适当的地方去引用
+## 3.ref
+* 1.在template模板中 绑定的标签中 ref="xxx"
+* 2.获取 this.$refs.xxx
+## 4.scoped 样式隔断 避免页面样式混乱
+## 5.安装yarn global add sass-loader node-sass
+## cnpm/npm install sass-loader node-sass --save
+## 6.scss 使用 样式嵌套 需要在style标签中 添加 lang="scss"

+ 2 - 0
vue2.0/vue高阶/hello_vue/package.json

@@ -9,6 +9,8 @@
   },
   "dependencies": {
     "core-js": "^3.8.3",
+    "node-sass": "^9.0.0",
+    "sass-loader": "^14.1.1",
     "vue": "^2.6.14"
   },
   "devDependencies": {

+ 40 - 10
vue2.0/vue高阶/hello_vue/src/App.vue

@@ -1,28 +1,58 @@
 <template>
   <div id="app">
-    <img alt="Vue logo" src="./assets/logo.png">
-    <HelloWorld msg="Welcome to Your Vue.js App"/>
+    <input v-model="day" />
+    <div @click="showMsg" ref="aaa">标签</div>
+    <Demo2 name="LiLi" sex="女" :age="20"></Demo2>
+    <!-- 
+      组件通信:
+        父组件 template标签中 ref="名称<aaa>"
+              mounted() this.$refs.aaa.$on("自定义的方法名<xx>",传送的方法)
+     -->
+    <Demo1 ref="getMain"></Demo1>
+    <!-- <button >按钮</button> -->
   </div>
 </template>
 
 <script>
-import HelloWorld from './components/HelloWorld.vue'
-
+import Demo1 from './components/Demo1.vue';
+import Demo2 from './components/Demo2.vue';
 export default {
-  name: 'App',
-  components: {
-    HelloWorld
-  }
+  name:"App",
+  data() {
+    return {
+      day:"星期三",
+      happy:"开心"
+    }
+  },
+  components:{
+    Demo1,
+    Demo2
+  },
+  created() {
+    console.log(this.day)
+  },
+  methods: {
+    aa() {
+      console.log("成功了")
+    },
+    showMsg() {
+      console.log(this.$refs.aaa,'ref属性')
+    }
+  },
+  mounted() {
+    this.$refs.getMain.$on("aab",this.aa)
+    // console.log(this.$refs.xxx)
+  },
 }
 </script>
 
 <style>
-#app {
+/* #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;
-}
+} */
 </style>

+ 65 - 0
vue2.0/vue高阶/hello_vue/src/components/Demo1.vue

@@ -0,0 +1,65 @@
+<template>
+  <div class="demo">
+    这是组件一
+    <div class="header">
+      <div class="left">我是一个logo</div>
+      <div class="mid">我是搜索框</div>
+      <div class="right">我是登录</div>
+    </div>
+    <button @click="getHand">接收父组件的传参</button>
+  </div>
+</template>
+
+<script>
+export default {
+  name:"Demo1",
+  data() {
+    return {
+
+    }
+  },
+  methods:{
+    getHand(){
+      this.$emit("aab")
+    }
+  }
+};
+</script>
+
+<style scoped lang="scss">
+.demo {
+  color: blue;
+}
+.header {
+  width: 100%;
+  height: 80px;
+  display: flex;
+  border-bottom: 1px solid #000;
+  .left {
+    flex: 2;
+    background: #0f0;
+  }
+  .mid {
+    flex: 5;
+    background: #f0f;
+  }
+  .right {
+    flex: 2;
+    background: #0ff;
+  }
+}
+//   .header .left {
+//     flex: 2;
+//     background: #0f0;
+//   }
+
+//   .header .mid {
+//     flex: 5;
+//     background: #f0f;
+//   }
+
+//   .header .right {
+//     flex: 2;
+//     background: #0ff;
+//   }
+</style>

+ 55 - 0
vue2.0/vue高阶/hello_vue/src/components/Demo2.vue

@@ -0,0 +1,55 @@
+<template>
+  <div class="demo">
+    这是组件二
+    我叫{{name}},是个{{sex}}孩,今年{{age}}
+  </div>
+</template>
+
+<script>
+/**
+ * 组件通信:
+ * 1.props 
+ * 父组件:<Child xxx="aaa" bbb="ccc"></Child>
+ * 子组件:
+ * props:['xxx','bbb']
+ * 子组件中使用时直接渲染
+ */
+export default {
+  name:"Demo2",
+  data() {
+    return {
+
+    }
+  },
+  
+  // 1.接收父组件简单传参
+  // props:['name','sex','age'],
+  // 2.类型限制
+  props:{
+    name:String,
+    sex:String,
+    age:Number,
+  }
+  // 3.接收参数判断
+  // props:{
+  //   name: {
+  //     type: String,
+  //     required: false
+  //   },
+  //   sex: {
+  //     type: String,
+  //     required: true
+  //   },
+  //   age: {
+  //     type: Number,
+  //     required: true
+  //   }
+  // }
+}
+</script>
+
+<style scoped>
+  .demo {
+    color: red;
+  }
+</style>

+ 0 - 58
vue2.0/vue高阶/hello_vue/src/components/HelloWorld.vue

@@ -1,58 +0,0 @@
-<template>
-  <div class="hello">
-    <h1>{{ msg }}</h1>
-    <p>
-      For a guide and recipes on how to configure / customize this project,<br>
-      check out the
-      <a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
-    </p>
-    <h3>Installed CLI Plugins</h3>
-    <ul>
-      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
-      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
-    </ul>
-    <h3>Essential Links</h3>
-    <ul>
-      <li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
-      <li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
-      <li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
-      <li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
-      <li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
-    </ul>
-    <h3>Ecosystem</h3>
-    <ul>
-      <li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
-      <li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
-      <li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
-      <li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
-      <li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
-    </ul>
-  </div>
-</template>
-
-<script>
-export default {
-  name: 'HelloWorld',
-  props: {
-    msg: String
-  }
-}
-</script>
-
-<!-- Add "scoped" attribute to limit CSS to this component only -->
-<style scoped>
-h3 {
-  margin: 40px 0 0;
-}
-ul {
-  list-style-type: none;
-  padding: 0;
-}
-li {
-  display: inline-block;
-  margin: 0 10px;
-}
-a {
-  color: #42b983;
-}
-</style>

+ 3 - 1
vue2.0/vue高阶/hello_vue/vue.config.js

@@ -1,4 +1,6 @@
 const { defineConfig } = require('@vue/cli-service')
 module.exports = defineConfig({
-  transpileDependencies: true
+  transpileDependencies: true,
+  // 关闭eslint校验
+  lintOnSave: false
 })