Vue学习笔记-9

Tailwind CSS

中文文档 - Tailwind CSS 中文文档

配置公共组件

  • 在babel.config.js文件中导入cli-plugin-babel
module.exports = {
  presets: ['@vue/cli-plugin-babel/preset'],
};
  • 在main.js中引入
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// 执行 ElementUI,传入一个配置对象
Vue.use(ElementUI, { size: 'small', zIndex: 3000 });

修改/src/components/test.vue

<template>
  <div>
    <!-- 测试信息一 -->
    <p>{{message.test1}}</p>
    <!-- 测试信息二 -->
    <p>{{message.test2}}</p>
    <!-- 发送请求按钮 -->
    <button @click="send">发送</button>
    <!-- 获取信息请求按钮 -->
    <button @click="getTest">接收</button>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        // 测试的信息,包括信息一和信息二
        message: {
          test1: 'Hello Shiyanlou!',
          test2: 'Hello World!',
        },
      };
    },
    methods: {
      // 发送请求方法
      send() {
        this.$http.post('test', this.message).then((res) => {
          // 利用三元表达式来完成不同的 message 状态展示信息
          res.data.flag
            ? this.$message.success(res.data.message)
            : this.$message.error(res.data.message);
        });
      },
      // 获取数据请求方法
      getTest() {
        this.$http.get('getTest', this.message).then((res) => {
          this.message = res.data;
        });
      },
    },
  };
</script>
image.png

配置公共组件

  • 解压assets文件夹至src目录下,放置静态图片
  • 在src/components/common目录下创建UserNav.vue
  • > 表示直接孩子节点, --或者__表示属性
<template>
  <div class="user-nav">
    <div class="nav-wrapper">
      <!-- logo -->
      <div class="logo">
        <img src="../../assets/img/nav-log.png" alt="前端开发俱乐部" />
      </div>
      <!-- 导航栏 el-menu  通过 :default-active 属性绑定对应的 activeIndex,从而达到刷新页面时默认激活选项的作用。-->
      <el-menu
        :default-active="activeIndex"
        class="el-menu-left"
        mode="horizontal"
      >
        <!-- 导航栏选项一 -->
        <el-menu-item index="1">
          <a href="https://www.html-js.cn/front-development___Nycd05pP"
            >前端开发</a
          >
        </el-menu-item>
        <!-- 导航栏选项二 -->
        <el-menu-item index="2">
          <a href="https://www.html-js.cn/document___Ek7skiaw">DoraCMS</a>
        </el-menu-item>
        <!-- 导航栏选项三 -->
        <el-menu-item index="3">
          <a href="https://www.html-js.cn/cmscase___SkCL09aCb">案例</a>
        </el-menu-item>
        <!-- 导航栏选项四 -->
        <el-menu-item index="4">
          <a href="https://www.html-js.cn/service___HyVhxcjAE">关于我</a>
        </el-menu-item>
      </el-menu>
      <!-- 登录注册导航栏 -->
      <el-menu class="el-menu-right" mode="horizontal" router>
        <!-- 导航栏选项一 -->
        <el-menu-item>
          <!-- 搜索框 -->
          <div id="search">
            <!-- 通过 v-show 来控制搜索框的出现与否 -->
            <input
              type="text"
              v-show="inputFlag"
              class="form-control"
              placeholder="请输入关键字"
            />
            <!-- 使用 ElementUI 的图标 -->
            <i
              class="el-icon-search fa-search"
              @click="inputFlag=!inputFlag"
            ></i>
          </div>
        </el-menu-item>
        <!-- 导航栏选项二 通过 index 进行跳转,跳转到登录页面 -->
        <el-menu-item index="login">登录</el-menu-item>
        <!-- 导航栏选项三 通过 index 进行跳转,跳转到注册页面 -->
        <el-menu-item index="reg">注册</el-menu-item>
      </el-menu>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        // 初始的 activeIndex
        activeIndex: '0',
        // 初始的搜索框状态
        inputFlag: false,
      };
    },
  };
</script>
<style scoped>
  .user-nav {
    width: 100%;
    background-color: #fff;
    border-bottom: solid 1px #e6e6e6;
  }

  .nav-wrapper {
    width: 60%;
    height: 60px;
    margin: 0 auto;
    position: relative;
  }

  .logo {
    display: inner-block;
    position: absolute;
    top: 5px;
    left: 5px;
  }

  .logo > img {
    height: 44px;
  }

/* 点击出来的下划线动效残留进行隐藏 */
  .el-menu.el-menu--horizontal {
    border-bottom: none;
  }

  .el-menu-left {
    position: relative;
    left: 250px;
  }

  .el-menu-right {
    position: absolute;
    top: 0;
    right: 20px;
  }

  .el-menu--horizontal > .el-menu-item {
    color: #000;
  }

/* 下拉框字体颜色*/
  .el-menu--horizontal .el-menu-item:not(.is-disabled):focus,
  .el-menu--horizontal .el-menu-item:not(.is-disabled):hover {
    color: #1e80d4;
  }

  #search {
    width: 220px;
    height: 100%;
    position: relative;
  }

  #search:active {
    color: #000;
    border: none;
  }

  #search input {
    width: 155px;
    height: 30px;
    position: relative;
    left: 10px;
    padding: 0 10px;
    box-shadow: 2px 1px 1px rgba(0, 0, 0, 0.075);
    border: none;
    -webkit-transition: all 0.3s ease-out 0s;
    transition: all 0.3s ease-out 0s;
    font-family: inherit;
    outline: none;
  }

  #search i {
    position: absolute;
    top: 22px;
    left: 190px;
  }
</style>
  • 创建公共组件Header.vue
<template>
  <div class="nav">
    <div class="header">
      <img src="../../assets/img/nav-log.png" alt="前端开发俱乐部" />
      <div class="search">
        <el-input
          placeholder="请输入关键字"
          v-model="searchData"
          class="search_input"
        >
        </el-input
        ><el-button type="primary" icon="el-icon-search">搜索</el-button>
      </div>
    </div>
    <div class="headerList">
      <el-menu :default-active="activeIndex" class="elList" mode="horizontal">
        <el-menu-item index="1"><a href="#">网站首页</a></el-menu-item>
        <el-menu-item index="2">
          <el-dropdown placement="top">
            <span class="el-dropdown-link">
              <a href="https://www.html-js.cn/front-development___Nycd05pP"
                >前端开发</a
              >
              <i></i>
            </span>
            <el-dropdown-menu class="option1" slot="dropdown">
              <el-dropdown-item>
                <a
                  href="https://www.html-js.cn/front-development/NodeJs___E1lagiaw"
                  >NodeJs</a
                >
              </el-dropdown-item>
              <el-dropdown-item>
                <a
                  href="https://www.html-js.cn/front-development/Express-Course___V1U2-a9le"
                  >Express</a
                >
              </el-dropdown-item>
              <el-dropdown-item>
                <a
                  href="https://www.html-js.cn/front-development/Jquery___4JknAqTv"
                  >Jquery</a
                >
              </el-dropdown-item>
              <el-dropdown-item>
                <a
                  href="https://www.html-js.cn/front-development/others___VyU4rLbt"
                  >其它</a
                >
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-menu-item>
        <el-menu-item index="3">
          <el-dropdown placement="top">
            <span class="el-dropdown-link">
              <a href="https://www.html-js.cn/document___Ek7skiaw">DoraCMS</a>
              <i></i>
            </span>
            <el-dropdown-menu class="option2" slot="dropdown">
              <el-dropdown-item
                ><a href="https://www.html-js.cn/document/course___EJFzljaw"
                  >原创教程</a
                ></el-dropdown-item
              >
              <el-dropdown-item
                ><a href="https://www.html-js.cn/document/soft___4yzPes6w"
                  >前端软件</a
                ></el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </el-menu-item>
        <el-menu-item index="4"
          ><a href="https://www.html-js.cn/cmscase___SkCL09aCb"
            >案例</a
          ></el-menu-item
        >
        <el-menu-item index="5"
          ><a href="https://www.html-js.cn/service___HyVhxcjAE"
            >关于我</a
          ></el-menu-item
        >
        <div class="users">
          <div class="user-avator">
            <img src="../../assets/img/img.jpg" />
          </div>
          <el-dropdown
            class="user-name"
            trigger="click"
            @command="handleCommand"
          >
            <span class="el-dropdown-link">
              {{username}}
              <i class="el-icon-caret-bottom"></i>
            </span>
            <!-- slot 设置下拉列表 -->
            <el-dropdown-menu slot="dropdown">
              <a href="https://github.com/doramart/DoraCMS" target="_blank">
                <el-dropdown-item>项目仓库</el-dropdown-item>
              </a>
              <el-dropdown-item divided command="loginout"
                >退出登录</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-menu>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        activeIndex: '#',
        searchData: '',
      };
    }, // 监控自定义属性
    computed: {
      username() {
        // 从本地存储中获取值
        let username = localStorage.getItem('ms_username');
        // 对获取到的值进行判断,如果从本地存储能够获取到值,则使用该值,如果不能获取到,则使用 data 中设置的值
        return username ? username : this.name;
      },
    },
    methods: {
      // 用户名下拉菜单选择事件
      handleCommand(command) {
        //退出登录事件
        if (command == 'loginout') {
          // 从本地存储中删除用户名
          localStorage.removeItem('ms_username');
          // 跳转到登录页面
          this.$router.push('/login');
        }
      },
    },
  };
</script>
<style scoped>
  * {
    margin: 0;
    padding: 0;
  }

  body {
    font: 15px 'Microsoft YaHei', Arial, Helvetica, sans-serif;
    color: #000;
    background: #f1f1f1;
    font-size: 15px;
  }

  img {
    border: 0;
    display: block;
  }

  ul,
  li {
    list-style: none;
  }

  a {
    text-decoration: none;
    color: #000;
  }

  a:hover {
    color: #218af1;
  }

  h1 {
    font-size: 28px;
  }

  h2 {
    font-size: 18px;
  }

  h3 {
    font-size: 16px;
  }

  i {
    font-style: normal;
    display: block;
  }

  span {
    display: block;
  }

  .nav {
    width: 100%;
  }

  .header {
    width: 60%;
    margin: 10px auto;
    position: relative;
  }

  .header > img {
    height: 50px;
  }

  .search {
    width: 30%;
    height: 80%;
    position: absolute;
    top: 10%;
    right: 0;
  }

  .search div {
    width: 70%;
    height: 100%;
    display: inline-block;
  }

  .search_input >>> input.el-input__inner {
    border-radius: 10px 0 0 10px;
    height: 40px;
  }

  .search_input >>> input.el-input__inner:focus {
    border-color: #dcdfe6;
  }

  .search button {
    width: 25%;
    height: 40px;
    position: absolute;
    top: 0;
    border-radius: 0 5px 5px 0;
  }

  .search >>> i {
    position: absolute;
    top: 13px;
    left: 20px;
  }

  .search >>> span {
    position: absolute;
    top: 13px;
    left: 35px;
  }

  .headerList {
    width: 100%;
    height: 50px;
    background-color: #1487f4;
  }

  .elList {
    width: 60%;
    height: 100%;
    line-height: 50px;
    background-color: #1487f4;
    margin: auto;
    position: relative;
  }

  .elList li {
    width: 100px;
    height: 100%;
    margin: 0 5px;
    line-height: 50px;
    display: inline;
    text-align: center;
    float: left;
    font-size: 15px;
    display: inline-block;
    color: #fff;
  }

  .el-menu--horizontal > .el-menu-item.is-active,
  .el-menu--horizontal .el-menu-item:not(.is-disabled):hover {
    background-color: rgb(9, 118, 220);
    border-bottom: 2px solid #409eff;
    color: #fff;
  }

  .elList li:nth-child(2) >>> span,
  .elList li:nth-child(3) >>> span {
    color: #fff;
  }

  .elList li:nth-child(2) >>> i:after,
  .elList li:nth-child(3) >>> i:after {
    content: '';
    position: absolute;
    right: -10px;
    top: 24px;
    width: 0;
    height: 0;
    border-width: 4px 4px 0;
    border-style: solid;
    border-color: #fff transparent transparent;
    -ms-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -webkit-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
  }

  .elList li:nth-child(2):hover i:after,
  .elList li:nth-child(3):hover i:after {
    transform: rotate(180deg);
  }

  .option1,
  .option2 {
    padding: 5px 0;
    width: 100px;
    border: none;
    border-radius: 0;
    top: 108px !important;
    background: rgb(9, 118, 220);
    z-index: 9;
  }

  .option1 li,
  .option2 li {
    width: 100%;
    padding: 0;
    text-align: center;
  }

  .option1 li a,
  .option2 li a {
    color: #fff;
  }

  .option1 >>> .popper__arrow,
  .option2 >>> .popper__arrow {
    border-bottom-width: 0 !important;
    border-left-width: 0 !important;
    border-right-width: 0 !important;
  }

  .el-dropdown-menu__item:focus,
  .el-dropdown-menu__item:not(.is-disabled):hover {
    background-color: #1487f4;
  }

  .option1 >>> .popper__arrow::after,
  .option2 >>> .popper__arrow::after {
    width: 0 !important;
    height: 0 !important;
    border-style: none;
    border: none;
    border-color: rgb(9, 118, 220);
  }

  .users {
    width: 160px;
    height: 100%;
    display: inline-block;
    text-align: center;
    line-height: 50px;
    float: right;
    margin-top: 0px;
  }

  .user-avator {
    displat: inline-block;
    margin-left: 20px;
    margin-top: 5px;
    float: left;
    cursor: pointer;
  }

  .user-avator img {
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }

  .user-name {
    width: 60px;
    display: inline-block;
    margin-left: 30px;
    float: left;
    cursor: pointer;
  }

  .user-name span {
    color: #fff;
    width: 80%;
  }

  .user-name i {
    width: 20%;
    display: inline-block;
  }

  .user-name i::before {
    color: #fff;
  }
</style>
  • 创建Footer.vue
<template>
  <div class="footer">
    <div class="footer_content">
      <ul>
        <li>
          <img
            src="https://static.shiyanlou.com/frontend/dist/img/4a4ab3d.svg"
            alt="实验楼"
          />
          <span>动手做实验,轻松学 IT</span>
        </li>
        <li>
          <img
            src="https://static.shiyanlou.com/frontend/dist/img/9f56dbd.png"
            alt="微信"
          />
          <span>我们的微信</span>
        </li>
      </ul>
      <div class="endNav">
        <b class="statement">站点声明:</b>
        <span
          >1、所有文章未经授权禁止转载、摘编、复制或建立镜像,如有违反,追究法律责任。</span
        >
        <span
          >2、本次训练营所使用的均为已经获得授权内容,大家可以在实验环境当中进行使用,不得用于其他商业活动。</span
        >
      </div>
    </div>
  </div>
</template>
<style scoped>
  span {
    display: block;
  }

  .footer {
    width: 100%;
    background-color: #333;
    position: relative;
    padding: 30px 0;
    overflow: hidden;
    color: #777;
    font-size: 14px;
  }

  .footer::before {
    content: '';
    background: #34aadc linear-gradient(to left, #1487f4, #5ac8fa, #007aff, #5ac8fa);
    height: 10px;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
  }

  .footer_content {
    width: 60%;
    margin: auto;
    overflow: hidden;
  }

  .footer_content li {
    float: left;
    margin: 0 10px;
    text-align: center;
  }

  .footer_content li img {
    height: 90px;
  }

  .endNav {
    margin-top: 10px;
  }

  .statement {
    font-size: 16px;
    color: #34aadc;
    margin-bottom: 15px;
    display: block;
  }
</style>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,110评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,443评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,474评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,881评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,902评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,698评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,418评论 3 419
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,332评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,796评论 1 316
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,968评论 3 337
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,110评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,792评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,455评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,003评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,130评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,348评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,047评论 2 355

推荐阅读更多精彩内容