bailing 1 周之前
父節點
當前提交
b5f5e38b69

+ 12 - 0
8.vue/高阶/1.归纳.md

@@ -0,0 +1,12 @@
+## 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.安装npm install sass-loader node-sass --save
+## 6.scss 使用 样式嵌套 需要在style标签中 添加 lang="scss"

文件差異過大導致無法顯示
+ 400 - 61
8.vue/高阶/my-project/package-lock.json


+ 2 - 0
8.vue/高阶/my-project/package.json

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

+ 21 - 17
8.vue/高阶/my-project/src/App.vue

@@ -1,28 +1,32 @@
 <template>
-  <div id="app">
-    <img alt="Vue logo" src="./assets/logo.png">
-    <HelloWorld msg="Welcome to Your Vue.js App"/>
+  <div>
+    主页
+    <!-- 3.使用组件 -->
+    <Demo1></Demo1>
+    <Demo2></Demo2>
+    <p ref="aaa">你好</p>
+    <button @click="getMain">获取</button>
   </div>
 </template>
 
 <script>
-import HelloWorld from './components/HelloWorld.vue'
-
+// 1.引入组件
+import Demo1 from './components/Demo1.vue';
+import Demo2 from './components/Demo2.vue';
 export default {
-  name: 'App',
-  components: {
-    HelloWorld
+  // 2.注册组件
+  components:{
+    Demo1,
+    Demo2
+  },
+  methods:{
+    getMain() {
+      console.log(this.$refs.aaa)
+    }
   }
 }
 </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;
-}
-</style>
+
+</style>

+ 17 - 0
8.vue/高阶/my-project/src/components/Demo1.vue

@@ -0,0 +1,17 @@
+<template>
+  <div id="demo">
+    <h1>这是第一个案例</h1>
+  </div>
+</template>
+
+<script>
+export default {
+
+}
+</script>
+
+<style scoped>
+#demo h1 {
+  color: #f00;
+}
+</style>

+ 57 - 0
8.vue/高阶/my-project/src/components/Demo2.vue

@@ -0,0 +1,57 @@
+<template>
+  <div id="demo">
+    <h1>这是第二个案例</h1>
+    <ul>
+      <li>
+        <a href>1</a>
+      </li>
+      <li>
+        <a href>2</a>
+      </li>
+      <li>
+        <a href>3</a>
+      </li>
+    </ul>
+  </div>
+</template>
+  
+  <script>
+export default {};
+</script>
+  
+<style scoped lang="scss">
+// * {
+//     list-style: none;
+// }
+// #demo h1 {
+//   color: #0f0;
+// }
+// #demo ul {
+//     overflow: hidden;
+// }
+// #demo ul li {
+//     float: left;
+//     margin-left: 10px;
+// }
+// #demo ul li a {
+//     color: #f00;
+// }
+* {
+  list-style: none;
+  #demo {
+    h1 {
+      color: #0f0;
+    }
+    ul {
+      overflow: hidden;
+      li {
+        float: left;
+        margin-left: 10px;
+        a {
+          color: #f00;
+        }
+      }
+    }
+  }
+}
+</style>

+ 0 - 58
8.vue/高阶/my-project/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
8.vue/高阶/my-project/vue.config.js

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

+ 1 - 1
8.vue/高阶/project1/src/App.vue

@@ -1,7 +1,7 @@
 <template>
   <div id="app">
     <nav>
-      <router-link to="/">Home</router-link> |
+      <router-link to="/">Home1</router-link> |
       <router-link to="/about">About</router-link>
     </nav>
     <router-view/>

部分文件因文件數量過多而無法顯示