vue3 element-plus 自动按需引入 + 打包 + 成为手机App + v3项目动画

d8a8e4e9e28a47c787adb119d53b0b85.gif

 

9a69fede8b2044a79dd834e3e48f20b4.png​前期回顾    89a5d93bcce94f7cbe42539567637cb3.gif​   

(移动端打包)一步一步,一步 从代码到,打包成为手机App,上传至nginx服务器 (Vue项目)_0.活在风浪里的博客-CSDN博客_移动端打包成app一步一步,一步 从代码到,打包成为手机App,上传至ngnix服务器 (Vue项目)https://blog.csdn.net/m0_57904695/article/details/122500485

element-plus 自动按需引入

  • 1.安装 

cnpm i unplugin-vue-components unplugin-auto-import -D
  • 2.配置:vue.config.js

const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')


//修改默认配置,配置跨域
//加载path模块
const path = require("path");
//定义resolve方法,把相对路径转换成绝对路径
const resolve = (dir) => path.join(__dirname, dir);

module.exports = {
    publicPath: "./", //解决打包白屏
    devServer: {
        // proxy: {
        //     "/api": {
        //         // http://www.sirfang.com/build/ajax_get_list这是完整路径,将com/后的路径重写路径为api
        //         // 1 目标路径 这里相当于公共的地址
        //         target: "http://m.sirfang.com/",
        //         // port: 9090, // 1.1端口号 默认的可以不配
        //         open: true, // 1.2运行项目自启
        //         //2 允许跨域
        //         changOrigin: true,
        //         hotOnly: true, //热更新
        //         //3 重写路径
        //         pathRewrite: {
        //             "^/api": "",
        //         },
        //     },
        // },
    },
    // 添加别名和跨域在项目开始就要先配好
    chainWebpack: (config) => {
        config.resolve.alias
            .set("@", resolve("src"))
            .set("assets", resolve("src/assets"))
            .set("views", resolve("src/views"))
            .set("components", resolve("src/components"));
    },
    //引入element-plus自动按需导入 插件都在这里引入!!!配合上面可实现打包体积优化,这里现在只是单独写了v3的自动引入
    configureWebpack: {
        plugins: [
            AutoImport({
                resolvers: [ElementPlusResolver()],
            }),
            Components({
                resolvers: [ElementPlusResolver()],
            }),
        ],
    }
};

页面使用:

<template>
  <div class="home">
    <el-row class="mb-4">
      <el-button round>Round</el-button>
      <el-button type="primary" round>Primary</el-button>
      <el-button type="success" round>Success</el-button>
      <el-button type="info" round>Info</el-button>
      <el-button type="warning" round>Warning</el-button>
      <el-button type="danger" round>Danger</el-button>
    </el-row>
  </div>
</template>

<script setup></script>

效果:

149327097c3f4fc3825bc679fe417060.gif

动画代码:

  • 位置app.vue 


<template>
  <!--
      vue3中移除了tag属性 新增了custom属性  custom可以用来自定义router-link的内容
      但是使用了之后会导致路由无法跳转 这时候需要v-slot="{navigate}" 通过事件触发navigate方法就能跳转页面
      假如有两个路由地址 第一个 /home 第二个是 /home/index
      exact-acitve-class 精确匹配后才会添加的class类名
      active-class 包含有就会添加的class类名
      vue2中的写法
      <router-link to="/" tag="button" exact-active-class="active">home</router-link>
    -->

  <router-link to="/" custom v-slot="{ navigate, isExactActive }">
    <!-- a 标签变成button -->
    <button @click="navigate" :class="isExactActive ? 'active' : ''">
      home
    </button>
  </router-link>
  |
  <router-link to="/about" custom v-slot="{ navigate, isExactActive }">
    <button @click="navigate" :class="isExactActive ? 'active' : ''">
      about
    </button>
  </router-link>
  <!-- 动画 -->
  <router-view v-slot="{ Component }">
    <div>
      <transition name="ani">
        <component :is="Component" class="pages"></component>
      </transition>
    </div>
  </router-view>
</template>

<style lang='scss'>
* {
  box-sizing: border-box;
}
html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

.pages {
  width: 100%;
  position: absolute;
  top: 50px;
  left: 0;
}
// 进入时
.ani-enter-from {
  left: 100%;
  transform: scale(0) rotate(-360deg);
  opacity: 0;
  background: blue;
}
//进入过程
.ani-enter-active {
  transition: all 1s linear;
}
//离开过程
.ani-leave-active {
  transition: all 1s linear;
  transform-origin: center;
}
//离开时
.ani-leave-to {
  left: -100%;
  transform: scale(0) rotate(360deg);
  opacity: 0;
  background: red;
}
.active {
  color: #d00;
}

</style>

完结:

祝大家越来越好,bug越来越少!

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
Element Plus是一个基于Vue 3的UI组件库,可以用于构建漂亮的用户界面。在使用Element Plus时,要在项目引入Element Plus的相关代码。 首先,在main.js或main.ts文件中,要导入Element Plus的库文件和样式文件。可以使用以下代码导入Element Plus: ```javascript import ElementPlus from 'element-plus' import 'element-plus/dist/index.css' ``` 然后,通过app.use()方法将Element Plus添加到Vue应用中: ```javascript app.use(ElementPlus) ``` 最后,使用app.mount()方法将Vue应用挂载到HTML页面上的特定元素上。 总结起来,你要在main.ts文件中导入Element Plus的库文件和样式文件,并通过app.use()方法将Element Plus添加到Vue应用中。这样就可以在Vue项目中使用Element Plus的组件了。 #### 引用[.reference_title] - *1* *2* [vue3使用Element-plus与TS(TypeScript)](https://blog.csdn.net/weixin_46019681/article/details/124950596)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Vue3.0 + Ts 项目框架搭建三:element-plus](https://blog.csdn.net/weixin_44209082/article/details/124228654)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

彩色之外

你的打赏是我创作的氮气加速动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值