vue3+ts项目-尚医通

目录

清除默认样式​编辑

引入全局组件

静态搭建和组件拆分

路由搭建

路由滚动行为:如 路由切换时 滚动条回到顶部。

首页的静态搭建

安装elementplus

轮播图:Carousel 走马灯

form表单

安装图标组件 icon

深度选择器(修改原本样式)

Layout 布局(el-row / el-col

医院等级/地区 静态结构搭建

卡片 静态组件 el-card

阿里图标库使用

CSS

垂直对齐align-items

分页 Pagination

代码 例

国际化

​编辑

 layout布局调整

 -> 顶到最右

从服务器调取数据 


清除默认样式

 出现报错:

Preprocessor dependency "sass" not found. Did you install it? Try `pnpm add -D sass`.

解决方法:安装scss: pnpm i sass

引入全局组件

全局组件:①引入组件, ②应用实例.component('标签', 组件)


静态搭建和组件拆分

顶部和底部的固定部分 拆分为单个组件,置于App.vue中


路由搭建

步骤:安装包vue-router -> 路由配置 -> 路由出口 -> 在入口文件 引入并安装

① 安装包: pnpm i vue-router

② 路由配置:新建 路由文件夹router、页面文件夹pages,在路由文件夹router中的 index.ts 进行以下路由配置

配置完毕,发现路由没有切换。原因:需指定路由组件展示区域 router-view

③ 配置路由出口 router-view,在上级路由中 写 路由出口

④ 在入口文件中,引入 vue-router 并安装

 路由配置的代码,以及其他写法:

import { createRouter,createWebHistory } from 'vue-router';
import Home from '@/pages/home/index.vue'
import Hospital from '@/pages/hospital/index.vue'

// createRouter方法 ,用于创建路由器实例,可以管理多个路由
export default createRouter({
    history: createWebHistory(),       // 路由模式的设置
    routes:[                           // 管理路由
    // 法一:重定向写法
        // {
        //     path: '/home',
        //     component: () => import('@/pages/home/index.vue') 
        // },
        // {
        //     path: '/hospital',
        //     component: () => import('@/pages/hospital/index.vue')
        // },
        // {
        //     path: '/',
        //     redirect: '/home'   //重定向
        // }
    // 法二(推荐):默认路由写法,缺省
        {
            path:'/',
            component: Home,
            children:[
                {
                    path:'/home',
                    component: Home
                }
            ]
        },
        {
            path: '/hospital',
            component: Hospital
        }
    ]
})

路由滚动行为:如 路由切换时 滚动条回到顶部。

首页的静态搭建

安装elementplus

①安装 element-plus:pnpm i element-plus,重新运行程序 pnpm run dev

② 按照官网 在路口文件main.ts中 进行引入

轮播图:Carousel 走马灯

(可以拆成单个组件

form表单

el-autocomplete 自动补全输入框

效果图:

.

安装图标组件 icon

pnpm i @element-plus/icons-vue,重新运行程序 pnpm run dev

② 引入图标 icon

深度选择器(修改原本样式)
  • >>>(原生css)
  • /deep/(lass中常用)
  • ::v-deep(sass中常用)

格式 如 ::v-deep .类名{}

注:scoped  让每个组件之间的样式相互不影响,不可或缺。

两种语法即可,::v-deep 可用  :deep(<inner-selector>)

Layout 布局(el-row / el-col
  • el-row 行,el-col 列,:span 自由组合布局(行 共占24份)

 效果图:

  • gutter  列间距

医院等级/地区 静态结构搭建
<!-- level.vue -->
<script setup lang='ts'>
    
</script>
<template>
    <div class="level">
        <h1>医院</h1>
        <div class="content">
            <div class="left">等级:</div>
            <ul class="hospital">
                <li class="active">全部</li>
                <li>三级甲等</li>
                <li>三级乙等</li>
                <li>二级甲等</li>
                <li>二级乙等</li>
                <li>一级甲等</li>
                <li>一级乙等</li>
            </ul>
            <div class="right"></div>
        </div>
    </div>
</template>
<style scoped lang='scss'>
.level{
    color: #7f7f7f;
    h1{
        font-weight: 900;
        margin: 10px 0;
    }
    .content{
        display: flex;
        .left {
            margin-right: 10px;
        }
        .hospital {
            display: flex;
            li{
                margin-right: 10px;
                &.active{
                    color: #55a6fe;
                }
            }
            li:hover{
                color: #55a6fe;
                // cursor: pointer;
            }
        }
    }
}
</style>
<!-- 地区 静态搭建 region.vue -->
<script setup lang='ts'>
    
</script>
<template>
    <div class="region">
        <div class="content">
            <div class="left">地区:</div>
            <ul>
                <li>全部</li>
                <li class="active">昌平区</li>
                <li>昌平区</li>
                <li>昌平区</li>
                <li>昌平区</li>
                <li>昌平区</li>
                <li>昌平区</li>
                <li>昌平区</li>
                <li>昌平区</li>
                <li>昌平区</li>
                <li>昌平区</li>
                <li>昌平区</li>
                <li>昌平区</li>
                <li v-for="item in 7" :key="item">昌平区</li>
            </ul>
        </div>
    </div>
</template>
<style scoped lang='scss'>
.region{
    color: #7f7f7f;
    margin-top: 10px;
    .content {
        display: flex;
        .left {
            margin-right: 10px;
            width: 59px;
        }
        ul {
            display: flex;
            flex-wrap: wrap;        //默认换行
            li{
                margin-right: 10px;
                margin-bottom: 10px;
                &.active {            //动态类
                    color: #55a6fe;
                }
            }
            li:hover {            //鼠标放上去
                color: #55a6fe;
                cursor: pointer;    //显示小手
            }
        }
    }
}
</style>
卡片 静态组件 el-card

el-card 卡片shadow = ‘always | hover | never’ 

代码如下

<!-- card.vue -->
<script setup lang='ts'>
    
</script>
<template>
    <el-card style="max-width: 480px" shadow="hover">
        <div class="content">
            <div class="left">
                <div class="hospital">北京医院</div>
                <div class="tip">
                    <div class="level">
                        <svg t="1711624714824" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4282" width="30" height="30"><path d="M190.193225 471.411583c14.446014 0 26.139334-11.718903 26.139334-26.13831 0-14.44499-11.69332-26.164916-26.139334-26.164916-0.271176 0-0.490164 0.149403-0.73678 0.149403l-62.496379 0.146333c-1.425466-0.195451-2.90005-0.295735-4.373611-0.295735-19.677155 0-35.621289 16.141632-35.621289 36.114522L86.622358 888.550075c0 19.949354 15.96767 35.597753 35.670407 35.597753 1.916653 0 3.808746 0.292666 5.649674 0l61.022819 0.022513c0.099261 0 0.148379 0.048095 0.24764 0.048095 0.097214 0 0.146333-0.048095 0.24457-0.048095l0.73678 0 0-0.148379c13.413498-0.540306 24.174586-11.422144 24.174586-24.960485 0-13.55983-10.760065-24.441669-24.174586-24.981974l0-0.393973-50.949392 0 1.450025-402.275993L190.193225 471.409536z" fill="#5D5D5D" p-id="4283"></path><path d="M926.52241 433.948343c-19.283182-31.445176-47.339168-44.172035-81.289398-45.546336-1.77032-0.246617-3.536546-0.39295-5.380544-0.39295l-205.447139-0.688685c13.462616-39.059598 22.698978-85.58933 22.698978-129.317251 0-28.349675-3.193739-55.962569-9.041934-82.542948l-0.490164 0.049119c-10.638291-46.578852-51.736315-81.31498-100.966553-81.31498-57.264215 0-95.466282 48.15065-95.466282 106.126063 0 3.241834-0.294712 6.387477 0 9.532097-2.996241 108.386546-91.240027 195.548698-196.23636 207.513194l0 54.881958-0.785899 222.227314 0 229.744521 10.709923 0 500.025271 0.222057 8.746198-0.243547c19.35686 0.049119 30.239721-4.817726 47.803749-16.116049 16.682961-10.761088 29.236881-25.50079 37.490869-42.156122 2.260483-3.341095 4.028757-7.075139 5.106298-11.20111l77.018118-344.324116c1.056052-4.053316 1.348718-8.181333 1.056052-12.160971C943.643346 476.446249 938.781618 453.944769 926.52241 433.948343zM893.82573 486.837924l-82.983993 367.783411-0.099261-0.049119c-2.555196 6.141884-6.879688 11.596106-12.872169 15.427364-4.177136 2.727111-8.773827 4.351098-13.414521 4.964058-1.49812-0.195451-3.046383 0-4.620227 0l-477.028511-0.540306-0.171915-407.408897c89.323375-40.266076 154.841577-79.670527 188.596356-173.661202 0.072655 0.024559 0.124843 0.049119 0.195451 0.072655 2.99931-9.137101 6.313799-20.73423 8.697079-33.164331 5.551436-29.185716 5.258771-58.123792 5.258771-58.123792-4.937452-37.98001 25.940812-52.965306 44.364417-52.965306 25.304316 0.860601 50.263777 33.656541 50.263777 52.326762 0 0 5.600555 27.563776 5.649674 57.190537 0.048095 37.366026-4.6673 56.847729-4.6673 56.847729l-0.466628 0c-5.872754 30.879288-16.214287 60.138682-30.464849 86.964654l0.36839 0.342808c-2.358721 4.815679-3.709485 10.220782-3.709485 15.943111 0 19.922748 19.088754 21.742187 38.765909 21.742187l238.761895 0.270153c0 0 14.666024 0.465604 14.690584 0.465604l0 0.100284c12.132318-0.638543 24.221658 5.207605 31.100322 16.409738 5.504364 9.016351 6.437619 19.6045 3.486404 28.988218L893.82573 486.837924z" fill="#5D5D5D" p-id="4284"></path><path d="M264.827039 924.31872c0.319272 0.024559 0.441045 0.024559 0.295735-0.024559 0.243547-0.048095 0.367367-0.074701-0.295735-0.074701s-0.539282 0.026606-0.271176 0.074701C264.43409 924.343279 264.532327 924.343279 264.827039 924.31872z" fill="#5D5D5D" p-id="4285"></path></svg>
                        <span>三级甲等</span>
                    </div>
                    <div class="time">
                        <svg t="1711625121054" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5575" width="30" height="30"><path d="M533.333333 938.666667C332.8 938.666667 170.666667 776.533333 170.666667 576S332.8 213.333333 533.333333 213.333333 896 375.466667 896 576 733.866667 938.666667 533.333333 938.666667z m0-42.666667c174.933333 0 320-145.066667 320-320S708.266667 256 533.333333 256 213.333333 401.066667 213.333333 576 358.4 896 533.333333 896zM640 128v42.666667h-213.333333V128h213.333333z m55.466667 256l29.866666 29.866667-174.933333 174.933333-29.866667-29.866667L695.466667 384z" fill="#444444" p-id="5576"></path></svg>
                        <span>2023</span>
                    </div>
                </div>
            </div>
            <div class="right">
                <img src="../../assets/images/logo.png" alt="">
            </div>
        </div>
    </el-card>
</template>
<style scoped lang='scss'>
.content { 
    display: flex;
    justify-content: space-between;
    .left {
        width: 60%;
        .tip {
            color: #7f7f7f;
            margin-top: 20px;
            display: flex;
            justify-content: space-between;
            .level {
                display: flex;
                align-items: center;
                span {
                    margin-left: 10px;
                }
            }
            .time  {
                display: flex;
                align-items: center;
                span {
                    margin-left: 10px;
                }
            }
        }
    }
    .right { 
        img {
            width: 50px;
            height: 50px;
        }
    }
}
</style>    

阿里图标库使用

直接使用,复制svg代码,代码中粘贴上去

CSS
垂直对齐align-items

解决:

分页 Pagination

代码 例
<el-pagination
      v-model:current-page="currentPage4"
      v-model:page-size="pageSize4"
      :page-sizes="[100, 200, 300, 400]"
      :small="small"             // 为true,表示小的分页器
      :disabled="disabled"        // 为true,禁用
      :background="background"
      layout="total, sizes, prev, pager, next, jumper"    // layout 布局, -> 顶到最右
      :total="400"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />


国际化

elementplus->指南->国际化,引入中文


 layout布局调整

对应下图,可通过换名字调整位置 

 -> 顶到最右

 layout中 的  ->  顶到最右侧(注意,若在弹性布局 display:flex 中会失效

从服务器调取数据 

axios二次封装

①安装 pnpm i axios

②  新建utils文件夹,request.ts中进行 axios 二次封装

  • 22
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值