当前位置: 首页 > article >正文

VUE+Tailwind网页开发

从nodejs官网下载安装包并安装:https://nodejs.org/zh-cn

参考vue官网步骤配置项目:https://cn.vuejs.org/guide/quick-start.html

$ npm create vue@latest
$ cd <your-project-name>
$ npm install

参考,安装vue-router:安装 | Vue Router

$ npm install vue-router@4

参考,安装Tailwind:Install Tailwind CSS with Vue 3 and Vite - Tailwind CSS

$ npm install -D tailwindcss@latest postcss@latest autoprefixer@latest
$ npx tailwindcss init -p

安装依赖:https://tailwindui.com/documentation#vue-installing-dependencies

npm install @headlessui/vue @heroicons/vue

项目目录如图:

./postcss.config.js文件内容如下:

export default {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}

./tailwind.config.js应该为如下内容:

/** @type {import('tailwindcss').Config} */
export default {
  content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'],
  theme: {
    extend: {},
  },
  plugins: [],
}

./indx.html文件内容如下:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <link rel="icon" href="./public/favicon.ico">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vite App</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.js"></script>
  </body>
</html>

./src/main.js文件内容如下:

import './main.css'

import { createApp } from 'vue'
import router from './router'
import App from './App.vue'

createApp(App)
  .use(router)
  .mount('#app')

 ./src/main.css文件内容如下:

@tailwind base;
@tailwind components;
@tailwind utilities;

 ./src/App.vue文件内容如下:

<template>
  <h1>Hello App!</h1>
  <!-- 添加几个组件看下渲染是否成功 -->
  <span class="inline-flex items-center rounded-md bg-gray-50 px-2 py-1 text-xs font-medium text-gray-600 ring-1 ring-inset ring-gray-500/10">Badge</span>
  <span class="inline-flex items-center rounded-md bg-red-50 px-2 py-1 text-xs font-medium text-red-700 ring-1 ring-inset ring-red-600/10">Badge</span>
  <span class="inline-flex items-center rounded-md bg-yellow-50 px-2 py-1 text-xs font-medium text-yellow-800 ring-1 ring-inset ring-yellow-600/20">Badge</span>
  <span class="inline-flex items-center rounded-md bg-green-50 px-2 py-1 text-xs font-medium text-green-700 ring-1 ring-inset ring-green-600/20">Badge</span>
  <span class="inline-flex items-center rounded-md bg-blue-50 px-2 py-1 text-xs font-medium text-blue-700 ring-1 ring-inset ring-blue-700/10">Badge</span>
  <span class="inline-flex items-center rounded-md bg-indigo-50 px-2 py-1 text-xs font-medium text-indigo-700 ring-1 ring-inset ring-indigo-700/10">Badge</span>
  <span class="inline-flex items-center rounded-md bg-purple-50 px-2 py-1 text-xs font-medium text-purple-700 ring-1 ring-inset ring-purple-700/10">Badge</span>
  <span class="inline-flex items-center rounded-md bg-pink-50 px-2 py-1 text-xs font-medium text-pink-700 ring-1 ring-inset ring-pink-700/10">Badge</span>
  <p>
    <strong>Current route path:</strong> {{ $route.fullPath }}
  </p>
  <nav>
    <RouterLink to="/">Go to Home</RouterLink>
    <RouterLink to="/about">Go to About</RouterLink>
  </nav>
  <main>
    <RouterView />
  </main>
</template>

 ./src/HomeView.vue文件内容如下:

<script>
export default {
  methods: {
    goToAbout() {
      this.$router.push('/about')
    },
  },
}
</script>

<template>
  <h2>HomeView</h2>
  <button @click="goToAbout">Go to About</button>
</template>

 ./src/AboutView.vue文件内容如下:

<script setup>
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const router = useRouter()
const route = useRoute()

const search = computed({
  get() {
    return route.query.search ?? ''
  },
  set(search) {
    router.replace({ query: { search } })
  }
})
</script>

<template>
  <h2>AboutView</h2>
  <label>
    Search: <input v-model.trim="search" maxlength="20">
  </label>
</template>

 运行项目:

npm run dev

运行结果如下,显示渲染成功:

Tailwind组件文档:https://tailwindcss.com/docs/installation


http://www.kler.cn/news/304340.html

相关文章:

  • 大数据中一些常用的集群启停命令
  • oracle 如何查询表被锁
  • Vue自定义组件:解密v-model,轻松实现双向数据绑定
  • Nacos rce-0day漏洞复现(nacos 2.3.2)
  • 如何准备技术面试?
  • 利用AI驱动智能BI数据可视化-深度评测Amazon Quicksight(二)
  • Stream流的思想和获取Stream流
  • 设计模式重新整理
  • 中秋出游热度十足!喆啡酒店如何巧妙捕捉多元旅游需求?
  • 遥感技术在生态系统碳储量、碳收支、碳排放、碳循环以及人为源排放反演等领域的技术发展,实践角度解决遥感技术在生态、能源、大气等领域的碳排放监测及模拟问题
  • C++ | Leetcode C++题解之第397题整数替换
  • Coggle数据科学 | 科大讯飞AI大赛:人岗匹配挑战赛 赛季3
  • 怎么将几个pdf合成为一个?把几个PDF合并成为一个的8种方法
  • opencv图像透视处理
  • 机器学习(西瓜书)第 6 章 支持向量机
  • Jupyter notebook配置与使用(安装过程+环境配置+运行实例)
  • redis基本数据结构-string
  • 关于OceanBase 多模一体化的浅析
  • 探索螺钉设计:部分螺纹与全螺纹,哪种更适合你的项目?
  • 学习笔记 韩顺平 零基础30天学会Java(2024.9.14)
  • HashMap在并发场景下的问题
  • hku-mars雷达相机时间同步方案-硬件(MID360与海康MV-CB060-10UMUC-S)
  • Spring-cloud-gateway报错问题总结
  • 卷轴模式系统中的任务起源探索与趣味性设计策略分析
  • 【大模型专栏—进阶篇】语言模型创新大总结——“后起之秀”
  • rocketmq-client5.2手动给生产者和消费者设置access-key和secret-key值
  • Sparse4D v1
  • 从零开始学PostgreSQL (十四):高级功能
  • 【来学Vue吧】创建一个Vue项目
  • 通过adb命令打开手机usb调试