前端工程化的CSS预处理工具之Stylus

简介: Stylus是一个非常流行的前端工程化打包工具,它可以帮助开发者快速构建具有可重用性和可维护性的前端项目,并且提供了完善的样式规则和自动化处理机制。

其中,Stylus的Task是一个非常重要的概念。 下面是一个简单的示例,演示如何在Vue.js中注册一个名为HelloWorld的组件,并使用Stylus进行组件开发,并实现Task。

html

Copy code

<template>  <div>    <divv-if="isLoading"class="loading-spinner">Loading...</div>    <divv-if="isVisible"class="visible-content">点击我</div>  </div></template><script>import HelloWorld from'./HelloWorld.vue'exportdefault {  data() {    return {      isLoading: true,      isVisible: false,    }  },  mounted() {    setTimeout(() => {      this.isLoading = false      this.isVisible = true    }, 1000)  }}</script><scriptsrc="https://unpkg.com/react@16.8.3/umd/react.development.js"></script><style>.loading-spinner {  position: absolute;  top: 50%;  left: 50%;  width: 50px;  height: 50px;  border-radius: 50%;  background-color: #ccc;  animation: spin 1s linear infinite;}@keyframes spin {  0% {    transform: rotate(0deg);  }  100% {    transform: rotate(360deg);  }}</style><React.createElement>  <divclassName="App">    <HelloWorld />    <divclassName="nav">      <ul>        <li><Linkto="/">首页</Link></li>        <li><Linkto="/about">关于</Link></li>      </ul>    </div>  </div></React.createElement><scriptsrc="https://unpkg.com/react-router-dom@4.3.3/umd/react-router-dom.development.js"></script><style>.App {  display: flex;  flex-direction: column;  align-items: center;  padding: 20px;}.nav {  display: flex;  flex-direction: column;  align-items: center;  margin-bottom: 20px;}.navli {  padding: 10px;  font-size: 16px;  text-align: center;}.nava {  color: #333;  text-decoration: none;}.nava:hover {  background-color: #333;}</style><scriptsrc="https://unpkg.com/vue@2.6.11/dist/vue.min.js"></script><style>.loading-spinner {  position: absolute;  top: 50%;  left: 50%;  width: 50px;  height: 50px;  border-radius: 50%;  background-color: #ccc;  animation: spin 1s linear infinite;}@keyframes spin {  0% {    transform: rotate(0deg);  }  100% {    transform: rotate(360deg);  }}</style><scriptsrc="https://unpkg.com/vue-router@1.7.2/dist/vue-router.min.js"></script><style>.App {  display: flex;  flex-direction: column;  align-items: center;  padding: 20px;}.nav {  display: flex;  flex-direction: column;  align-items: center;  margin-bottom: 20px;}.navli {  padding: 10px;  font-size: 16px;  text-align: center;}.nava {  color: #333;  text-decoration: none;}.nava:hover {  background-color: #333;}</style><scriptsrc="https://unpkg.com/vue-router-link-active@1.0.5/dist/vue-router-link-active.min.js"></script><scriptsrc="https://unpkg.com/axios@0.20.0/dist/axios.min.js"></script><style>.loading-spinner {  position: absolute;  top: 50%;  left: 50%;  width: 50px;  height: 50px;  border-radius: 50%;  background-color: #ccc;  animation: spin 1s linear infinite;}@keyframes spin {  0% {    transform: rotate(0deg);  }  100% {    transform: rotate(360deg);  }}</style><scriptsrc="https://unpkg.com/vue-router-link-active@1.0.5/dist/vue-router-link-active.min.js"></script><scriptsrc="https://unpkg.com/axios@0.20.0/dist/axios.min.js"></script><style>.App {  display: flex;  flex-direction: column;  align-items: center;  padding: 20px;}.nav {  display: flex;  flex-direction: column;  align-items: center;  margin-bottom: 20px;}.navli {  padding: 10px;  font-size: 16px;  text-align: center;}.nava {  color: #333;  text-decoration: none;}.nava:hover {  background-color:

目录
相关文章
|
1天前
|
前端开发 JavaScript API
前端工程化-babel、corejs、postcss
前端工程化-babel、corejs、postcss
7 0
|
1天前
|
前端开发
前端 CSS 经典:省略号
前端 CSS 经典:省略号
7 0
|
1天前
|
前端开发
前端 CSS 经典:clip、clip-path
前端 CSS 经典:clip、clip-path
3 0
|
1天前
|
前端开发
前端 CSS 经典:box-shadow
前端 CSS 经典:box-shadow
8 1
|
1天前
|
前端开发
前端 css 经典:选择器速记
前端 css 经典:选择器速记
6 0
|
1天前
|
前端开发 容器
前端 css 经典:grid 栅格布局
前端 css 经典:grid 栅格布局
9 1
|
3天前
|
移动开发 HTML5
HTML5/CSS3粒子效果进度条代码
HTML5/CSS3进度条应用。这款进度条插件在播放进度过程中出现粒子效果,就像一些小颗粒从进度条上散落下来
19 0
HTML5/CSS3粒子效果进度条代码
|
3天前
|
移动开发 前端开发 JavaScript
:掌握移动端开发:HTML5 与 CSS3 的高效实践
:掌握移动端开发:HTML5 与 CSS3 的高效实践 “【5月更文挑战第6天】”
27 1
|
3天前
|
缓存 移动开发 前端开发
【专栏:HTML与CSS前端技术趋势篇】HTML与CSS在PWA(Progressive Web Apps)中的应用
【4月更文挑战第30天】PWA(Progressive Web Apps)结合现代Web技术,提供接近原生应用的体验。HTML在PWA中构建页面结构和内容,响应式设计、语义化标签、Manifest文件和离线页面的创建都离不开HTML。CSS则用于定制主题样式、实现动画效果、响应式布局和管理字体图标。两者协同工作,保证PWA在不同设备和网络环境下的快速、可靠和一致性体验。随着前端技术进步,HTML与CSS在PWA中的应用将更广泛。
|
3天前
|
前端开发 JavaScript 开发者
【专栏:HTML与CSS前端技术趋势篇】前端框架(React/Vue/Angular)与HTML/CSS的结合使用
【4月更文挑战第30天】前端框架React、Vue和Angular助力UI开发,通过组件化、状态管理和虚拟DOM提升效率。这些框架与HTML/CSS结合,使用模板语法、样式管理及组件化思想。未来趋势包括框架简化、Web组件标准采用和CSS在框架中角色的演变。开发者需紧跟技术发展,掌握新工具,提升开发效能。