在这章中,主要对喵喵商城(meowmall)
项目使用的前端技术ES6
和Vue.js
做一定的了解与基础学习,达到够用的水准即可,因为之前在java_web
的学习中写过前端的代码,能够实现基本的页面展示以及与后端的交互,学习新技术可以简化开发流程。
ES6
是JavaScript
的语言规范,因为我们开发出来的JavaScript
代码,最终还是要在浏览器(或者Node这样的环境)中运行,而生产浏览器的厂家很多,所以需要指定一套标准规范。
Vue.js
是一种框架,因为很多应用都有共同的功能,一些好的做法也可以在不同应用之间共享,所以,就有了框架,可以用来简化开发流程。
ES6 let & const
var
在{}
之外也起作用,多次声明同一var
类型的变量不会报错,var
可以变量提升(可以在声明前调用,即只要在任意地方声明过,全局任意地方都可以直接使用)
let
在{}
之外不起作用,let
多次声明会报错,只能声明一次,let
不存在变量提升(声明和被调用的顺序不能反)
const
在声明之后就不允许改变了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1.0" > <meta http-equiv ="X-UA-Compatible" content ="ie=edge" > <title > Document</title > </head > <body > <script > const a = 1 ; a = 3 ; </script > </body > </html >
解构表达式
支持let arr = [1,2,3];
和let [a,b,c] = arr;
这种语法
1 2 3 4 5 6 7 8 let arr = [1 ,2 ,3 ];let a = arr[0 ];let b = arr[1 ];let c = arr[2 ];let [a,b,c] = arr;console .log(a,b,c)
支持对象解析:const { name: abc, age, language } = person;
冒号代表改名
1 2 3 4 5 6 7 8 9 10 11 12 13 14 const person = { name : "jack" , age : 21 , language : ['java' , 'js' , 'css' ] } const { name : abc, age, language } = person;console .log(abc, age, language)
字符串扩展
1 2 3 4 5 6 let str = "hello.vue" ;console .log(str.startsWith("hello" )); console .log(str.endsWith(".vue" )); console .log(str.includes("e" )); console .log(str.includes("hello" ));
字符串模板
1 2 3 4 5 let ss = `<div> <span>hello world<span> </div>` ;console .log(ss);
字符串插入变量或表达式
1 2 3 4 5 6 7 8 function fun ( ) { return "这是一个函数" } let info = `我是${abc} ,今年${age + 10 } 了, 我想说: ${fun()} ` ;console .log(info);
函数优化
原来想要函数默认值得这么写b = b || 1
; 现在可以直接写了function add2(a, b = 1) {}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 function add (a, b ) { b = b || 1 ; return a + b; } console .log(add(10 )); function add2 (a, b = 1 ) { return a + b; } console .log(add2(20 ));
函数不定参数function fun(...values) {}
1 2 3 4 5 6 function fun (...values ) { console .log(values.length) } fun(1 , 2 ) fun(1 , 2 , 3 , 4 )
支持箭头函数(lambda
表达式),还支持使用{}
结构传入对象的成员
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 var print = obj => console .log(obj);print("hello" ); var sum = function (a, b ) { c = a + b; return a + c; } var sum2 = (a, b ) => a + b;console .log(sum2(11 , 12 ));var sum3 = (a, b ) => { c = a + b; return a + c; } console .log(sum3(10 , 20 ))const person = { name : "jack" , age : 21 , language : ['java' , 'js' , 'css' ] } function hello (person ) { console .log("hello," + person.name) } var hello2 = ({name} ) => console .log("hello," +name);hello2(person);
对象优化
可以获取map
的键值对等Object.keys()
、values
、entries
1 2 3 4 5 6 7 8 9 10 const person = { name : "jack" , age : 21 , language : ['java' , 'js' , 'css' ] } console .log(Object .keys(person)); console .log(Object .values(person)); console .log(Object .entries(person));
Object.assgn(target,source1,source2)
合并
1 2 3 4 5 6 7 8 const target = { a : 1 };const source1 = { b : 2 };const source2 = { c : 3 };Object .assign(target, source1, source2);console .log(target);
const person2 = { age, name }
声明对象简写
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 const age = 23 const name = "张三" const person1 = { age : age, name : name }const person2 = { age, name } console .log(person2);let person3 = { name : "jack" , eat : function (food ) { console .log(this .name + "在吃" + food); }, eat2 : food => console .log(person3.name + "在吃" + food), eat3 (food ) { console .log(this .name + "在吃" + food); } } person3.eat("香蕉" ); person3.eat2("苹果" ) person3.eat3("橘子" );
...
代表取出该对象所有属性拷贝到当前对象。let someone = {...p1}
1 2 3 4 5 6 7 8 9 10 11 let p1 = { name : "Amy" , age : 15 }let someone = { ...p1 }console .log(someone) let age1 = { age : 15 }let name1 = { name : "Amy" }let p2 = {name :"zhangsan" }p2 = { ...age1, ...name1 } console .log(p2)
map和reduce 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 let arr = ['1' , '20' , '-5' , '3' ]; arr = arr.map(item => item*2 ); console .log(arr);let result = arr.reduce((a,b )=> { console .log("上一次处理后:" +a); console .log("当前正在处理:" +b); return a + b; },100 ); console .log(result)
promise
以前在嵌套Ajax的时候很繁琐,解决方案:
把Ajax
封装到Promise
中,赋值给let p
在Ajax
中成功使用resolve(data)
,交给then
处理
失败使用reject(err)
,交给catch
处理p.then().catch()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 corse_score_10.json 得分 { "id" : 100 , "score" : 90 } user.json 用户 { "id" : 1 , "name" : "zhangsan" , "password" : "123456" } user_corse_1.json 课程 { "id" : 10 , "name" : "chinese" }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 function get (url, data ) { return new Promise ((resolve, reject ) => { $.ajax({ url : url, data : data, success : function (data ) { resolve(data); }, error : function (err ) { reject(err) } }) }); } get("mock/user.json" ) .then((data ) => { console .log("用户查询成功~~~:" , data) return get(`mock/user_corse_${data.id} .json` ); }) .then((data ) => { console .log("课程查询成功~~~:" , data) return get(`mock/corse_score_${data.id} .json` ); }) .then((data )=> { console .log("课程成绩查询成功~~~:" , data) }) .catch((err )=> { console .log("出现异常" ,err) });
模块化
模块化就是把代码进行拆分,方便重复利用。类似于java中的导包, 而JS换了个概念,是导模块。
模块功能主要有两个命令构成export
和import
export
用于规定模块的对外接口
import
用于导入其他模块提供的功能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 user.js var name = "jack" var age = 21 function add (a,b ) { return a + b; } export {name,age,add}hello.js export default { sum (a, b ) { return a + b; } } main.js import abc from "./hello.js" import {name,add} from "./user.js" abc.sum(1 ,2 ); console .log(name);add(1 ,3 );
Vue
MVVM思想
M:model 包括数据和一些基本操作
V:view 视图,页面渲染结果
VM:View-model,模型与视图间的双向操作(无需开发人员干涉)
视图和数据通过VM绑定起来,model里有变化会自动地通过Directives填写到视view中,视图表单中添加了内容也会自动地通过DOM Listeners保存到模型中。
基础案例 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1.0" > <meta http-equiv ="X-UA-Compatible" content ="ie=edge" > <title > Document</title > </head > <body > <div id ="app" > <input type ="text" v-model ="num" > v-model实现双向绑定 <button v-on:click ="num++" > 点赞</button > v-on:click绑定事件,实现自增 <button v-on:click ="cancel" > 取消</button > 回到自定义的方法 <h1 > {{name}} ,非常帅,有{{num}}个人为他点赞{{hello()}}</h1 > </div > <script src ="./node_modules/vue/dist/vue.js" > </script > <script > let vm = new Vue({ el : "#app" , data : { name : "张三" , num : 1 }, methods :{ cancel ( ) { this .num -- ; }, hello ( ) { return "1" } } }); 还可以在html控制台vm.name </script > </body > </html >
v-text、v-html.html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1.0" > <meta http-equiv ="X-UA-Compatible" content ="ie=edge" > <title > Document</title > </head > <body > <div id ="app" > {{msg}} {{1+1}} {{hello()}}<br /> 用v-html取内容 <span v-html ="msg" > </span > <br /> 原样显示 <span v-text ="msg" > </span > </div > <script src ="../node_modules/vue/dist/vue.js" > </script > <script > new Vue({ el :"#app" , data :{ msg :"<h1>Hello</h1>" , link :"http://www.baidu.com" }, methods :{ hello ( ) { return "World" } } }) </script > </body > </html >
插值表达式 花括号:只能写在标签体内,不能用在标签内。
用v-bind解决
{{}}必须有返回值
单向绑定v-bind 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1.0" > <meta http-equiv ="X-UA-Compatible" content ="ie=edge" > <title > Document</title > </head > <body > <div id ="app" > <a v-bind:href ="link" > gogogo</a > <span v-bind:class ="{active:isActive,'text-danger':hasError}" :style ="{color: color1,fontSize: size}" > 你好</span > </div > <script src ="../node_modules/vue/dist/vue.js" > </script > <script > let vm = new Vue({ el :"#app" , data :{ link : "http://www.baidu.com" , isActive :true , hasError :true , color1 :'red' , size :'36px' } }) </script > </body > </html >
双向绑定v-model 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1.0" > <meta http-equiv ="X-UA-Compatible" content ="ie=edge" > <title > Document</title > </head > <body > <div id ="app" > 精通的语言: <input type ="checkbox" v-model ="language" value ="Java" > java<br /> <input type ="checkbox" v-model ="language" value ="PHP" > PHP<br /> <input type ="checkbox" v-model ="language" value ="Python" > Python<br /> 选中了 {{language.join(",")}} </div > <script src ="../node_modules/vue/dist/vue.js" > </script > <script > let vm = new Vue({ el :"#app" , data :{ language : [] } }) </script > </body > </html >
v-on 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1.0" > <meta http-equiv ="X-UA-Compatible" content ="ie=edge" > <title > Document</title > </head > <body > <div id ="app" > <button v-on:click ="num++" > 点赞</button > <button @click ="cancel" > 取消</button > <h1 > 有{{num}}个赞</h1 > <div style ="border: 1px solid red;padding: 20px;" v-on:click.once ="hello" > 大div <div style ="border: 1px solid blue;padding: 20px;" @click.stop ="hello" > 小div <br /> <a href ="http://www.baidu.com" @click.prevent.stop ="hello" > 去百度</a > </div > </div > <input type ="text" v-model ="num" v-on:keyup.up ="num+=2" @keyup.down ="num-=2" @click.ctrl ="num=10" > <br /> 提示: </div > <script src ="../node_modules/vue/dist/vue.js" > </script > <script > new Vue({ el :"#app" , data :{ num : 1 }, methods :{ cancel ( ) { this .num--; }, hello ( ) { alert("点击了" ) } } }) </script > </body > </html >
v-for 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1.0" > <meta http-equiv ="X-UA-Compatible" content ="ie=edge" > <title > Document</title > </head > <body > <div id ="app" > <ul > <li v-for ="(user,index) in users" :key ="user.name" v-if ="user.gender == '女'" > 当前索引:{{index}} ==> {{user.name}} ==> {{user.gender}} ==>{{user.age}} <br > 对象信息: <span v-for ="(v,k,i) in user" > {{k}}=={{v}}=={{i}};</span > </li > </ul > <ul > <li v-for ="(num,index) in nums" :key ="index" > </li > </ul > </div > <script src ="../node_modules/vue/dist/vue.js" > </script > <script > let app = new Vue({ el : "#app" , data : { users : [{ name : '柳岩' , gender : '女' , age : 21 }, { name : '张三' , gender : '男' , age : 18 }, { name : '范冰冰' , gender : '女' , age : 24 }, { name : '刘亦菲' , gender : '女' , age : 18 }, { name : '古力娜扎' , gender : '女' , age : 25 }], nums : [1 ,2 ,3 ,4 ,4 ] }, }) </script > </body > </html >
v-if和v-show 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1.0" > <meta http-equiv ="X-UA-Compatible" content ="ie=edge" > <title > Document</title > </head > <body > <div id ="app" > <button v-on:click ="show = !show" > 点我呀</button > <h1 v-if ="show" > if=看到我....</h1 > <h1 v-show ="show" > show=看到我</h1 > </div > <script src ="../node_modules/vue/dist/vue.js" > </script > <script > let app = new Vue({ el : "#app" , data : { show : true } }) </script > </body > </html >
v-else和v-else-if 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1.0" > <meta http-equiv ="X-UA-Compatible" content ="ie=edge" > <title > Document</title > </head > <body > <div id ="app" > <button v-on:click ="random=Math.random()" > 点我呀</button > <span > {{random}}</span > <h1 v-if ="random>=0.75" > 看到我啦?! > = 0.75 </h1 > <h1 v-else-if ="random>=0.5" > 看到我啦?! > = 0.5 </h1 > <h1 v-else-if ="random>=0.2" > 看到我啦?! > = 0.2 </h1 > <h1 v-else > 看到我啦?! < 0.2 </h1 > </div > <script src ="../node_modules/vue/dist/vue.js" > </script > <script > let app = new Vue({ el : "#app" , data : { random : 1 } }) </script > </body > </html >
计算属性和侦听器 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1.0" > <meta http-equiv ="X-UA-Compatible" content ="ie=edge" > <title > Document</title > </head > <body > <div id ="app" > <ul > <li > 西游记; 价格:{{xyjPrice}},数量:<input type ="number" v-model ="xyjNum" > </li > <li > 水浒传; 价格:{{shzPrice}},数量:<input type ="number" v-model ="shzNum" > </li > <li > 总价:{{totalPrice}}</li > {{msg}} </ul > </div > <script src ="../node_modules/vue/dist/vue.js" > </script > <script > new Vue({ el : "#app" , data : { xyjPrice : 99.98 , shzPrice : 98.00 , xyjNum : 1 , shzNum : 1 , msg : "" }, computed : { totalPrice ( ) { return this .xyjPrice*this .xyjNum + this .shzPrice*this .shzNum } }, watch : { xyjNum (newVal,oldVal ) { if (newVal>=3 ){ this .msg = "库存超出限制" ; this .xyjNum = 3 }else { this .msg = "" ; } } }, }) </script > </body > </html >
过滤器 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1.0" > <meta http-equiv ="X-UA-Compatible" content ="ie=edge" > <title > Document</title > </head > <body > <div id ="app" > <ul > <li v-for ="user in userList" > {{user.id}} ==> {{user.name}} ==> {{user.gender == 1?"男":"女"}} ==> {{user.gender | genderFilter}} ==> {{user.gender | gFilter}} </li > </ul > </div > <script src ="../node_modules/vue/dist/vue.js" > </script > <script > Vue.filter("gFilter" , function (val ) { if (val == 1 ) { return "男~~~" ; } else { return "女~~~" ; } }) let vm = new Vue({ el : "#app" , data : { userList : [ { id : 1 , name : 'jacky' , gender : 1 }, { id : 2 , name : 'peter' , gender : 0 } ] }, filters : { filters 定义局部过滤器,只可以在当前vue实例中使用 genderFilter (val ) { if (val == 1 ) { return "男" ; } else { return "女" ; } } } }) </script > </body > </html >
组件化 在大型应用开发的时候,页面可以划分成很多部分。往往不同的页面,也会有相 同的部分。
例如可能会有相同的头部导航。
但是如果每个页面都自开发,这无疑增加了我们开发的成本。所以我们会把页面 的不同分拆分成立的组件,然后在不同页面就可以共享这些组件,避免重复开发。
在vue里,所有的vue实例都是组件
组件其实也是一个vue实例,因此它在定义时也会接收:data、methods、生命周期函等
不同的是组件不会与页面的元素綁定,否则就无法复用了,因此没有el属性。 但是组件渲染需要html模板,所以增加了template属性,值就是HTML模板 全局组件定义完毕,任何vue实例都可以直接在HTML中通过组件名称来使用组了 data必须是一个函数,不再是一个对象。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1.0" > <meta http-equiv ="X-UA-Compatible" content ="ie=edge" > <title > Document</title > </head > <body > <div id ="app" > <button v-on:click ="count++" > 我被点击了 {{count}} 次</button > <counter > </counter > <counter > </counter > <counter > </counter > <counter > </counter > <counter > </counter > <button-counter > </button-counter > </div > <script src ="../node_modules/vue/dist/vue.js" > </script > <script > Vue.component("counter" , { template : `<button v-on:click="count++">我被点击了 {{count}} 次</button>` , data ( ) { return { count : 1 } } }); const buttonCounter = { template : `<button v-on:click="count++">我被点击了 {{count}} 次~~~</button>` , data ( ) { return { count : 1 } } }; new Vue({ el : "#app" , data : { count : 1 }, components : { 'button-counter' : buttonCounter } }) </script > </body > </html >
生命周期和钩子函数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 <!DOCTYPE html > <html lang ="en" > <head > <meta charset ="UTF-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1.0" > <meta http-equiv ="X-UA-Compatible" content ="ie=edge" > <title > Document</title > </head > <body > <div id ="app" > <span id ="num" > {{num}}</span > <button @click ="num++" > 赞!</button > <h2 > {{name}},有{{num}}个人点赞</h2 > </div > <script src ="../node_modules/vue/dist/vue.js" > </script > <script > let app = new Vue({ el : "#app" , data : { name : "张三" , num : 100 }, methods : { show ( ) { return this .name; }, add ( ) { this .num++; } }, beforeCreate ( ) { console .log("=========beforeCreate=============" ); console .log("数据模型未加载:" + this .name, this .num); console .log("方法未加载:" + this .show()); console .log("html模板未加载:" + document .getElementById("num" )); }, created : function ( ) { console .log("=========created=============" ); console .log("数据模型已加载:" + this .name, this .num); console .log("方法已加载:" + this .show()); console .log("html模板已加载:" + document .getElementById("num" )); console .log("html模板未渲染:" + document .getElementById("num" ).innerText); }, beforeMount ( ) { console .log("=========beforeMount=============" ); console .log("html模板未渲染:" + document .getElementById("num" ).innerText); }, mounted ( ) { console .log("=========mounted=============" ); console .log("html模板已渲染:" + document .getElementById("num" ).innerText); }, beforeUpdate ( ) { console .log("=========beforeUpdate=============" ); console .log("数据模型已更新:" + this .num); console .log("html模板未更新:" + document .getElementById("num" ).innerText); }, updated ( ) { console .log("=========updated=============" ); console .log("数据模型已更新:" + this .num); console .log("html模板已更新:" + document .getElementById("num" ).innerText); } }); </script > </body > </html >
使用Vue脚手架开发
全局安装webpack 1 npm install webpack -g
全局安装vue脚手架 2 npm install -g @vue/cli-init
3 初始化vue项目vue init webpack appname
:vue脚手架使用webpack
模板初始化一个appname
项目 4 启动vue项目 项目的package.json
中有scripts
,代表我们能运行的命令npm start = npm run dev
: 启动项目npm run build
:将项目打包
使用element-ui
推荐使用 npm 的方式安装,它能更好地和 webpack 打包工具配合使用。
npm i element-ui -S
在 main.js 中写入以下内容:
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
参考资料
[1] Java项目《谷粒商城》Java架构师 | 微服务 | 大型电商项目_哔哩哔哩_bilibili
[2] 从前慢-谷粒商城篇章1_unique_perfect的博客-CSDN博客_从前慢 谷粒商城