vue create entry-animate
只需要简单的项目框架即可,routervuex 都不用;
<template><divclass="list-container gradientAnimation":style="{ animationDelay: `${index * speed}ms` }"><slot> </slot></div>
</template><script>
import { defineComponent } from "vue";export default defineComponent({name: "entryList",// 注册你的组件props: {// 列表的下标index: {type: Number,default: 0,},// 出现的速度speed: {type: Number,default: 100,},},// 定义一个组件的 emitted 事件,当在 emits 选项中定义了原生事件 (如 click) 时,将使用组件中的事件替代原生事件侦听器。
});
</script><style scoped>
.gradientAnimation {animation-name: gradient;animation-duration: 0.85s;animation-fill-mode: forwards;opacity: 0;
}/* 不带前缀的放到最后 */
@keyframes gradient {0% {opacity: 0;transform: translate(-100px, 0px);}100% {opacity: 1;transform: translate(0px, 0px);}
}
</style>
<script setup>
import { reactive } from "vue";
import entryList from "./package/entryList/index.vue";const list = reactive([1, 2, 3, 4, 5, 7, 8, 7, 4, 5, 1, 2, 4, 4, 84, 2, 1, 2, 1, 2, 3, 4, 5, 7, 8, 7,4, 5, 1, 2, 4, 4, 84, 2, 1, 2, 1, 2, 3, 4, 5, 7, 8, 7, 4, 5, 1, 2, 4, 4, 84,2, 1, 2, 1, 2, 3, 4, 5, 7, 8, 7, 4, 5, 1, 2, 4, 4, 84, 2, 1, 2, 1, 2, 3, 4, 5,7, 8, 7, 4, 5, 1, 2, 4, 4, 84, 2, 1, 2,
]);
</script><template><div class="list-contaienr"><div class="" v-for="(item, index) in list" :key="index" v-entry="index"><entryList :index="index"><div class="item">{{ item }}</div></entryList></div></div>
</template><style scoped>
.list-contaienr {text-align: center;width: 100%;background: #c0c7b5;
}.item {background-color: #fff;margin-bottom: 10px;
}.gradientAnimation {animation-name: gradient;animation-duration: 0.85s;animation-fill-mode: forwards;opacity: 0;
}/* 不带前缀的放到最后 */
@keyframes gradient {0% {opacity: 0;transform: translate(-100px, 0px);}100% {opacity: 1;transform: translate(0px, 0px);}
}
</style>
Vue
提供的install
方法,这个方法会在使用Vue.use(plugin)
时被调用,这样就能让我们需要导出的组件注册到全局, 就可以在任意组件中像使用子组件一样直接使用导出的组件rc/package/index.js
import entryList from "./entryList/index.vue";// --target lib 指定打包的目录
// --name 打包后的文件名
// --dest 打包后的文件夹名称const componentArr = [entryList];export default {install: (app) => {// 注册组件componentArr.forEach((item) => {appponent(item.name, item); // item.name就是引入组件中的name属性,所以每个组件都需要name});},
};
// --target lib 指定打包的目录
// --name 打包后的文件名
// --dest 打包后的文件夹名称"scripts": {"serve": "vue-cli-service serve","build": "vue-cli-service build","lint": "vue-cli-service lint","package": "vue-cli-service build --target lib ./src/package/index.js --name entry-animate --dest entry-animate"},
npm run package
{"name": "entry-animate","version": "1.0.0","description": "","main": "entry-animatemon.js","scripts": {"test": "echo "Error: no test specified" && exit 1"},"author": "","private": false, // 是否设为私有包"license": "ISC"
}
可去npm官网注册: ;
也可以通过命令行注册
首先得将npm镜像源切换为官方的源,大部分人的镜像源可能为淘宝镜像源,其他的也不行,想发布就得切换为npm官方镜像源
npm config set registry=
注册
npm adduser
依次填入账号、密码、邮箱, 填写完成后邮箱会收到一个npm发的一次性密码(也就是验证码) 再次填入即可,如果还未填写就报错,多半是得需要
npm publish
发布成功的图
npm中文网 官网 然后去 npm 上查找一下自己发的包 我的 entry-animate
npm i entry-animate
具体的效果,就不上传视频了
搞定收工,这样发布就完成了,以后就能从npm 拉包进行项目开发了
npm 链接 entry-animate - npm
本文发布于:2024-01-28 04:29:33,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063873754782.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |