今日任务:
npm uninstall -g vue-cli npm install -g @vue/cli@4.5.17
组件的引入分三步1导入2注册3使用,最后组件的使用要在< div >,
组件的使用要在< div >
组件的使用要在< div >
组件的使用要在< div >
在项目 根目录 下增加vue.config.js文件
// vue.config.js module.exports = { lintOnSave: false }
package.json引入"vue-router": "^3.2.0"
后npm install
"dependencies": { "core-js": "^3.8.3", "element-ui": "^2.15.9", "vue": "^2.6.14", "vue-router": "^3.2.0" }, "devDependencies": { "@babel/core": "^7.12.16", "@babel/eslint-parser": "^7.12.16", "@vue/cli-plugin-babel": "~5.0.0", "@vue/cli-plugin-eslint": "~5.0.0", "@vue/cli-service": "~5.0.0", "eslint": "^7.32.0", "eslint-plugin-vue": "^8.0.3", "vue-template-compiler": "^2.6.14" },
再在新建src/router/router.js
然后在main.js引入import router from './router/router'
挂载new Vue({router,})
首先新建vue2项目后
在package.json 目录下安装Element
npm i element-ui -S
在main.js引入
import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; Vue.use(ElementUI);
新建Home.vue加入(加不加div都可)
<template> <div><el-container style="height: 500px; border: 1px solid #eee"> <el-aside width="200px" style="background-color: rgb(238, 241, 246)"> <el-menu :default-openeds="['1', '3']"> <el-submenu index="1"> <template slot="title"><i class="el-icon-message"></i>导航一</template> <el-menu-item-group> <template slot="title">分组一</template> <el-menu-item index="1-1">选项1</el-menu-item> <el-menu-item index="1-2">选项2</el-menu-item> </el-menu-item-group> <el-menu-item-group title="分组2"> <el-menu-item index="1-3">选项3</el-menu-item> </el-menu-item-group> <el-submenu index="1-4"> <template slot="title">选项4</template> <el-menu-item index="1-4-1">选项4-1</el-menu-item> </el-submenu> </el-submenu> <el-submenu index="2"> <template slot="title"><i class="el-icon-menu"></i>导航二</template> <el-menu-item-group> <template slot="title">分组一</template> <el-menu-item index="2-1">选项1</el-menu-item> <el-menu-item index="2-2">选项2</el-menu-item> </el-menu-item-group> <el-menu-item-group title="分组2"> <el-menu-item index="2-3">选项3</el-menu-item> </el-menu-item-group> <el-submenu index="2-4"> <template slot="title">选项4</template> <el-menu-item index="2-4-1">选项4-1</el-menu-item> </el-submenu> </el-submenu> <el-submenu index="3"> <template slot="title"><i class="el-icon-setting"></i>导航三</template> <el-menu-item-group> <template slot="title">分组一</template> <el-menu-item index="3-1">选项1</el-menu-item> <el-menu-item index="3-2">选项2</el-menu-item> </el-menu-item-group> <el-menu-item-group title="分组2"> <el-menu-item index="3-3">选项3</el-menu-item> </el-menu-item-group> <el-submenu index="3-4"> <template slot="title">选项4</template> <el-menu-item index="3-4-1">选项4-1</el-menu-item> </el-submenu> </el-submenu> </el-menu> </el-aside> <el-container> <el-header style="text-align: right; font-size: 12px"> <el-dropdown> <i class="el-icon-setting" style="margin-right: 15px"></i> <el-dropdown-menu slot="dropdown"> <el-dropdown-item>查看</el-dropdown-item> <el-dropdown-item>新增</el-dropdown-item> <el-dropdown-item>删除</el-dropdown-item> </el-dropdown-menu> </el-dropdown> <span>王小虎</span> </el-header> <el-main> <el-table :data="tableData"> <el-table-column prop="date" label="日期" width="140"> </el-table-column> <el-table-column prop="name" label="姓名" width="120"> </el-table-column> <el-table-column prop="address" label="地址"> </el-table-column> </el-table> </el-main> </el-container> </el-container></div> </template> <script> export default { name: "Home", data() { const item = { date: '2016-05-02', name: '王小虎', address: '上海市普陀区金沙江路 1518 弄' }; return { tableData: Array(2).fill(item) } } } </script> <style scoped> .el-header { background-color: #B3C0D1; color: #333; line-height: 60px; } .el-aside { color: #333; } </style>
我们知道,此组件的名称是Home,
name:"Home"
在引入的时候分三步
在App.vue下
<template> <div id="app"> <Home/> </div> </template> <script> import HelloWorld from './components/HelloWorld.vue' import Home from "@/components/Home"; export default { name: 'App', components: { HelloWorld,Home } } </script> <style> </style>
第一步
import HelloWorld from './components/HelloWorld.vue'
第二步
export default { name: 'App', components: { HelloWorld,Home } }
第三步,在div里面引入
<Home/>
记录一次愚蠢的bug
中午调试新建vuecli ,引入element,data()数据不显示?
重新装了一次vue create vue7 就好了
第三节第四节是引入操作,