【前端】Vue项目:旅游App-(1)搭建项目、重置css、配置router和store(pinia)

2023-11-14

创建项目

npm init vue@latest

本项目相关选择:

在这里插入图片描述
安装相关依赖:

npm install

试着跑一下:

npm run dev

出现以下语句表示成功:

在这里插入图片描述

搭建和配置项目:项目目录结构划分

在这里插入图片描述

  • assets:静态资源,如img,css、font、audio
  • components:抽取组件
  • hooks:逻辑
  • mock:mock模拟数据
  • router:配置路由
  • service:网络请求
  • utils:工具
  • views:页面

重置CSS

重置css分为两步:

  • normalize.css
  • reset.css

normalize.css

是总结了大部分前端重置的重置代码。

在终端安装:

npm install normalize.css

在main.js引入:

import "normalize.css"

reset.css

/**
 * Eric Meyer's Reset CSS v2.0 (http://meyerweb.com/eric/tools/css/reset/)
 * http://cssreset.com
 */
 
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video{
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  font-weight: normal;
  vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section{
  display: block;
}
ol, ul, li{
  list-style: none;
}
blockquote, q{
  quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after{
  content: '';
  content: none;
}
table{
  border-collapse: collapse;
  border-spacing: 0;
}
 
/* custom */
a{
  color: #7e8c8d;
  text-decoration: none;
  -webkit-backface-visibility: hidden;
}
::-webkit-scrollbar{
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track-piece{
  background-color: rgba(0, 0, 0, 0.2);
  -webkit-border-radius: 6px;
}
::-webkit-scrollbar-thumb:vertical{
  height: 5px;
  background-color: rgba(125, 125, 125, 0.7);
  -webkit-border-radius: 6px;
}
::-webkit-scrollbar-thumb:horizontal{
  width: 5px;
  background-color: rgba(125, 125, 125, 0.7);
  -webkit-border-radius: 6px;
}
html, body{
  width: 100%;
  font-family: "Arial", "Microsoft YaHei", "黑体", "宋体", "微软雅黑", sans-serif;
}
body{
  line-height: 1;
  -webkit-text-size-adjust: none;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
html{
  overflow-y: scroll;
}
 
/*清除浮动*/
.clearfix:before,
.clearfix:after{
  content: " ";
  display: inline-block;
  height: 0;
  clear: both;
  visibility: hidden;
}
.clearfix{
  *zoom: 1;
}
 
/*隐藏*/
.dn{
  display: none;
}

目录结构

在这里插入图片描述
reset是重置样式表。
我们把所有的css文件写进index.css,如:

@import "./reset.css";

然后在main中引入index.css:注意,normalize.css不要放进index.css,它们是分开的。

import "./assets/css/index.css"

配置router

目标:四个页面,点就跳转。

在这里插入图片描述

对应页面组件

目录结构:

在这里插入图片描述
页面内容(以favor为例):

<template>
    <div class="favor">
        <h2>favor</h2>
    </div>
</template>

<script setup>

</script>

<style lang="less" scoped>

</style>

index.js

安装依赖:

npm install vue-router

index.js:

import {createRouter,createWebHashHistory} from 'vue-router'

const router=createRouter({
    history:createWebHashHistory(),
    routes:[
        {
            path:'/',
            redirect:'/home' //重定向到home
        },
        {
            path:'/home',
            component:()=>import("@/views/home/home.vue")
        },
        {
            path:'/favor',
            component:()=>import("@/views/favor/favor.vue")
        },
        {
            path:'/order',
            component:()=>import("@/views/order/order.vue")
        },
        {
            path:'/message',
            component:()=>import("@/views/message/message.vue")
        },
    ]
})

export default router

在main中引入并use:

import router from './router'

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

在App中写router-view

<template>
    <div class="app">
        <router-view/>
        <router-link to="/home">首页</router-link>
        <router-link to="/favor">收藏</router-link>
        <router-link to="/order">订单</router-link>
        <router-link to="/message">消息</router-link>
    </div>
</template>

效果:

在这里插入图片描述
我们这里要把router-view写在router-link的上面。我们要点击跳转到的路由界面在选择的上面。

配置store

我们这里用的是pinia。

安装依赖:

npm install pinia

配置:

import {createPinia} from 'pinia'

const pinia = createPinia()

export default pinia

在main中引入并use:

import pinia from './store'

createApp(App).use(router).use(pinia).mount('#app')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【前端】Vue项目:旅游App-(1)搭建项目、重置css、配置router和store(pinia) 的相关文章

随机推荐

  • Qt QToolButton和QListWidget的使用

    1 本篇简介 本篇主要演示QListWidget的使用 还涉及工具箱 QToolBox 和工具按钮 QToolButton 的使用 还会通过Action创建工具按钮的下拉菜单和QListWidget的组件的快捷菜单 展示如下图 2 QLis
  • Redis之string类型的三大编码解读

    目录 string类型的三大编码 int 编码 embstr 编码 raw 编码 明明没有超过阈值 为什么变成raw 查看数据类型相关命令 redis看看类型 type key 看看编码 object encoding debug结构 de
  • 2021年wsl2中配置Ubuntu18.04+CUDA+Pytorch深度学习环境完全版

    2021年4月 wsl2 中配置深度学习环境完全版 windows10 RTX3090 wsl2 ubuntu18 04 cuda cudatoolkit11 0 cudnn11 0 gnome anaconda3 pycharm 写在前面
  • 使用tinyproxy简易搭建代理服务器

    需要 腾讯云服务器或阿里云服务器 虚拟机 步骤 第一步 在自己的云服务器上安装 tinyproxy 如果是 Ubuntu 就使用 apt install y tinyproxy 如果是 Centos 则使用 yum install y ti
  • 图像去模糊:MIMO-UNet 模型详解

    本内容主要介绍实现图像去模糊的 MIMO UNet 模型 论文 Rethinking Coarse to Fine Approach in Single Image Deblurring 代码 官方 https github com cho
  • opengles3.0 学习,顶点着色器(六)

    opengles3 0 学习 顶点着色器 六 顶点着色器输入包括 属性 用顶点数组提供的逐顶点数据 统一变量和统一变量缓冲区 顶点着色器使用的不变数据 采样器 代表顶点着色器使用的纹理的特殊统一变量类型 着色器程序 顶点着色器的源码 顶点着
  • 基于人脸的常见表情识别(3)——模型搭建、训练与测试

    基于人脸的常见表情识别 3 模型搭建 训练与测试 模型搭建与训练 1 数据接口准备 2 模型定义 3 模型训练 模型测试 本 Task 是 基于人脸的常见表情识别 训练营的第 3 课 如果你未学习前面的课程 请从 Task1 开始学习 本
  • 基于std::queue C++11 线程安全队列。

    网上看到的封装不错 记录一下 非原创 pragma once include
  • JAVA实现大文件多线程下载,提速30倍!(提供exe版)

    JAVA实现大文件多线程下载 提速30倍 前言 兄弟们看到这个标题可能会觉得是个标题党 为了解决疑虑 我们先来看下最终的测试结果 测试云盘下载的文件 46M 自己本地最大下载速度 2M 1 单线程下载 总耗时 603s 2 多线程下载 50
  • DDPMs扩散模型Pytorch代码实现附详细注释

    本文相当于是对The Annotated Diffusion Model的代码理解后加的注释 很详尽 具体有些公式图片不太好显示 在vx公众号 一蓑烟雨晴 回复 100 下载notebook版本的代码文件 import math from
  • 多目标跟踪笔迹十三:Learning by tracking Siamese CNN for robust target association

    1 Introduce 本文介绍了一种在行人跟踪背景下处理数据关联任务的新方法 引入了一种两阶段学习方案去匹配 检测对 首先 对 Siamese 卷积神经网络 CNN 进行了训练 以学习描述两个输入图像块之间的局部时空结构 聚合像素值和光流
  • 安装Ambari 2.7.5 + HDP3.1.5(附安装包)

    目录 前置准备 1 安装包准备 2 服务器配置 3 配置静态IP 4 配置主机名 5 关闭防火墙及selinux 6 配置ssh互信 7 安装pssh工具 非必须 8 配置ntp时钟同步 9 设置swap 10 关闭透明大页面 11 安装h
  • ubuntu创建自己的git远程仓库

    准备工作 先弄来一个服务器 可以先自行租赁一个服务器例如华为云 阿里云 腾讯云等等 这些服务器都可以哪个便宜就选择哪个吧 然后安装一个ubuntu的系统 这边我自用的是ubuntu系统 其他的系统没用搭建过 如果是Linux的系统大致都一样
  • 人工智能汇总---政策-应用--技术

    2017 8 2018 6月 那些脑袋迷糊的日子 不知啥是人工智能 接下来一步一步去了解 从大政策 到媒体 企业 学校 自己动手 逐步对人工智能有个初步的了解 下面对精华网址汇总 供有共同爱好的学习 讨论群 366244662 2017 8
  • VASP输入INCAR文件

    欢迎来到我的博客 坚持比努力重要 文章目录 欢迎来到我的博客 坚持比努力重要 目录 VASP输入INCAR文件 初始I O设置 读入 读出 Electronic Relaxation 电子步 Ionic Relaxation 离子步 Pol
  • Arduino使用Esp32-cam开发版

    首先你需要先准备一些硬件 1 Esp32 Cam开发版 2 TY OV2640 v2 0摄像头 3 烧录底座 可以用USB TTL 我用的是Esp8266的烧录底座 4 杜邦线母线x5 颜色不做要求 开始填坑 贴个大佬的玩法 如果你在开发版
  • 获取outputstream大小_java从输入流中获取数据并返回字节数组示例

    代码如下 import java io ByteArrayOutputStream import java io InputStream 从输入流中获取数据并以字节数组返回 public class StreamTool 从输入流获取数据
  • 神州网信政府版win10远程

    今天去客户公司部署系统 本来想着开好远程后马上回来远程操作 哪知道客户服务器安装的是 神州网信政府版win10远程 遇到一堆问题 处理了半天 记录下 1 参考 Windows10神州网信版的远程桌面开启 神州网信 远程桌面 dawn的博客
  • Using the SG3525 PWM Controller - Explanation and Example: Circuit Diagram / Schematic of Push-Pull

    5 Using the SG3525 PWM Controller Explanation and Example Circuit Diagram Schematic of Push Pull Converter PWM is used i
  • 【前端】Vue项目:旅游App-(1)搭建项目、重置css、配置router和store(pinia)

    文章目录 创建项目 搭建和配置项目 项目目录结构划分 重置CSS normalize css reset css 目录结构 配置router 对应页面组件 index js 配置store 创建项目 npm init vue latest