• 使用vue搭建应用二加入element


    安装使用 element

    1.安装

    yarn add element-ui

    2.使用

    (1)在 main.js 中引入 element

    main.js 为修改

    import Vue from 'vue'
    import App from './App'
    import router from './router'
    import ElementUI from 'element-ui'
    import 'element-ui/lib/theme-chalk/index.css'
    
    Vue.config.productionTip = false
    
    Vue.use(ElementUI)
    
    /* eslint-disable no-new */
    new Vue({
      el: '#app',
      router,
      render: h => h(App)
    })

    (2)简单应用

    修改 src/components/HelloWorld.vue

    <template>
      <div class="hello">
        <h1>{{ msg }}</h1>
        <el-row>
          <el-button icon="el-icon-search" circle></el-button>
          <el-button type="primary" icon="el-icon-edit" circle></el-button>
          <el-button type="success" icon="el-icon-check" circle></el-button>
          <el-button type="info" icon="el-icon-message" circle></el-button>
          <el-button type="warning" icon="el-icon-star-off" circle></el-button>
          <el-button type="danger" icon="el-icon-delete" circle></el-button>
        </el-row>
      </div>
    </template>
    <script> export default { name: 'HelloWorld', data () { return { msg: 'Welcome to Your Vue.js App' } } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> h1, h2 { font-weight: normal; } </style>

    重新启动,预览 http://localhost:8080,变为

    (3)修改路由

    将src下的components改为views,在views下添加页面Login.vue、Home.vue、404.vue

    Login.vue

    View Code

    Home.vue

    View Code

    404.vue

    View Code

    修改src/router/index.js,添加对应的路由

    import Vue from 'vue'
    import Router from 'vue-router'
    import Login from '@/views/Login'
    import Home from '@/views/Home'
    import NotFound from '@/views/404'
    
    Vue.use(Router)
    
    export default new Router({
      routes: [
        {
          path: '/',
          name: 'Home',
          component: Home
        }, {
          path: '/login',
          name: 'Login',
          component: Login
        }
        , {
          path: '/404',
          name: 'NotFound',
          component: NotFound
        }
      ]
    })

    重新启动服务

    http://localhost:8080/#/

     http://localhost:8080/#/login显示Login页面

  • 相关阅读:
    从开发者角色到产品角色转换
    前端开发做什么?
    最近的前端开发认知总结
    最近的Vue知识总结
    计算机网络
    javascript 字符串加密的几种方法
    JSON数据解析
    JAVA 自定义状态码
    JAVA jdbc获取数据库连接
    JAVA通过md5方法进行加密
  • 原文地址:https://www.cnblogs.com/baby123/p/11857164.html
Copyright © 2020-2023  润新知