uniapp - 填充頁面

在上一篇文章中,創建了一個空白的文章模塊頁面。在這一篇文章,讓我們來向頁面中填充內容。

目錄

  • 頁面效果
  • 涉及uniapp組件
    • 1.view
    • 2.swiper
    • 3.scroll-view
    • 4.屬性解讀
      • 1) class="style1 style2 .."
      • 2) circular單屬性無賦值
      • 3) :autoplay="autoplay"
      • 4) @scrolltolower=“lower”屬性前加@
  • 一、頂部banner圖
  • 二、靜態按鈕列表
  • 三、橫向滾動圖
  • 四、動態列表 + 詳情跳轉
  • 五、詳情頁面
  • 參考資料

頁面效果

填充前的頁面
![填充前](https://img-blog.csdnimg.cn/direct/2a1b2998b39a4c89a3a70ce1a7b68526.png

填充后的頁面
在這里插入圖片描述

涉及uniapp組件

1.view

視圖容器,類似傳統html中的div,用于包裹各種元素的內容。

2.swiper

滑塊視圖,可上下和左右滑動,一般作為banner輪播圖。
在這里插入圖片描述

3.scroll-view

區域滾動視圖,有縱向滾動和橫向滾動。
在這里插入圖片描述

4.屬性解讀

例子:
a.<swiper class="article-swiper" circular :autoplay="autoplay" :indicator-dots="true" :duration="1000"></swiper>b.<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" show-scrollbar="true" @scrolltoupper="upper"@scrolltolower="lower" @scroll="scroll" ></scroll-view>

1) class=“style1 style2 …”

class賦值的是自定義樣式,具體樣式定義內容在vue文件的

2) circular單屬性無賦值

等價于circular=“true”,屬性的靜態綁定寫法,不會變更

3) :autoplay=“autoplay”

vue中屬性的動態綁定寫法,綁定一個參數,參數值可根據界面操作(比如button、switch)變更

4) @scrolltolower=“lower”屬性前加@

vue中動態綁定方法的寫法

一、頂部banner圖

/pages/article/article.vue

<template><view class="u-p-l-10 u-p-r-10">/*** class="article-swiper":樣式為style中自定義的.article-swiper{...}* circular:是否采用銜接滑動* :autoplay="autoplay":是否自動切換,此處設置動態綁定autoplay參數* indicator-dots:是否顯示面板展示點* duration="1000":滑動動畫時長* */<swiper class="article-swiper" circular :autoplay="autoplay" indicator-dots duration="1000">/*** swiper下的每個swiper-item是一個滑動切換區域*/<swiper-item><view class="article-swiper-item uni-bg-red">red</view></swiper-item><swiper-item><view class="article-swiper-item uni-bg-green">green</view></swiper-item><swiper-item><view class="article-swiper-item uni-bg-blue">blue</view></swiper-item></swiper><view ><view>自動播放</view>/*** switch 開關選擇器* :checked="autoplay":是否選中,由autoplay參數決定* @change="changeAutoplay":checked改變時觸發change事件,綁定changeAutoplay方法*/<switch :checked="autoplay" @change="changeAutoplay" /></view></view>
</template>
<script>import config from "@/common/config.js"export default {data() {return {// 自動播放參數:默認值是trueautoplay: true}},methods: {changeAutoplay(e) {// 點擊時開關狀態取反this.autoplay = !this.autoplay}}}
</script>
<style lang="scss" scoped>.article-swiper {height: 300rpx;}.article-swiper-item {display: block;height: 300rpx;line-height: 300rpx;text-align: center;}.uni-bg-red {background-color: rgb(255, 85, 127);}.uni-bg-green {background-color: rgb(170, 255, 0);}.uni-bg-blue {background-color: rgb(85, 170, 255);}
</style>

二、靜態按鈕列表

/pages/article/article.vue

<template><view class="u-p-l-10 u-p-r-10"><view><view class="rowClass"><u-row>/*** u-row、u-col:流式柵格系統,隨著屏幕或視口分為 24 份,可以迅速簡便地創建布局。* span:定義u-col應該跨越的列數* v-for="(item,index) in navList":列表渲染指令*	(1) navList:data中的源數據數組*  (2) item:data數據navList數組的別名*  (3) index:navList數組的索引* @tap="clickNav(item):方法暫未定義** image:按鈕圖片* item.name:靜態按鈕名稱*/<u-col span="3" text-align="center" v-for="(item,index) in navList" :key="index"><view class="u-padding-20" @tap="clickNav(item)" hover-class="hoverClass"><image :src="item.src" style="width: 90rpx;height: 90rpx;" mode="widthFix"></image><view class="tabName">{{item.name}}</view></view></u-col></u-row></view></view></view>
</template>
<script>import config from "@/common/config.js"export default {data() {return {navList:[{name:"發布文章",url:"pages/center/publishArticle"},{name:"我的文章",url:"pages/center/myArticle"},{name:"所有文章",url:"pages/center/allArticle"},{name:"瀏覽記錄"}]}}}
</script>
<style lang="scss" scoped>
.rowClass{border-radius: 8px;background-color: rgb(255, 255, 255);margin-top: 10rpx;text-align: center;}.hoverClass{background-color: #E4E7ED;}.tabName{font-size: 28rpx;color: $u-main-color;}
</style>

三、橫向滾動圖

/pages/article/article.vue

<template><view class="u-p-l-10 u-p-r-10"><view><view ><text>滾動文章banner</text></view><view>/*** :scroll-top="scrollTop":設置豎向滾動條位置* scroll-y="true":允許縱向滾動* show-scrollbar="true":是否出現滾動條,僅支持app-nvue* @scrolltoupper="upper":滾動到頂部/左邊,會觸發 scrolltoupper 事件* @scrolltolower="lower":滾動到底部/右邊,會觸發 scrolltolower 事件* @scroll="scroll":滾動時觸發**/<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" show-scrollbar="true" @scrolltoupper="upper"@scrolltolower="lower" @scroll="scroll" ><view id="demo1" class="scroll-view-item uni-bg-red">A</view><view id="demo2" class="scroll-view-item uni-bg-green">B</view><view id="demo3" class="scroll-view-item uni-bg-blue">C</view></scroll-view></view></view></view>
</template>
<script>import config from "@/common/config.js"export default {data() {return {scrollTop: 0,old: {scrollTop: 0}}},methods: {upper: function(e) {console.log(e)},lower: function(e) {console.log(e)},scroll: function(e) {console.log(e)this.old.scrollTop = e.detail.scrollTop}}}
</script>
<style lang="scss" scoped>
.uni-bg-red {background-color: rgb(255, 85, 127);}.uni-bg-green {background-color: rgb(170, 255, 0);}.uni-bg-blue {background-color: rgb(85, 170, 255);}.scroll-Y {height: 300rpx;}.scroll-view-item {height: 300rpx;line-height: 300rpx;text-align: center;font-size: 36rpx;}
</style>

四、動態列表 + 詳情跳轉

/pages/article/article.vue

<template><view class="u-p-l-10 u-p-r-10"><view><view ><text>滾動文章列表</text></view><view class="wrap"><scroll-view scroll-Y style="heignt: 100%;width 100%"><view>/*** @click="clickContent(item):點擊觸發clickContent方法,跳轉詳情頁面*/<view class="tabSwiper" v-for="(item,value) in articleList" :key="item.id" @click="clickContent(item)"><view class="top"><view class="left"><u-icon name="bell" :size="35" color="#2979ff"></u-icon><view class="title">{{ item.title }}</view><u-icon name="arrow-right" color="rgb(203,203,203)" :size="26"></u-icon></view><view class="right">{{ item.createTime }}</view></view><view class="item"><view class="content"><view class="title u-line-2">{{ item.content }}</view></view></view></view></view></scroll-view></view></view></view>
</template>
<script>import config from "@/common/config.js"export default {data() {return {pageNum:1,pageSize:50,articleList: [],}},onLoad() {this.getArticleList();},methods: {clickContent(item){if(item.id){this.$u.route('/pages/article/content', {id: item.id});}},getArticleList(){let url = "/api/cmsApi/findArticleList";this.$u.get(url,{pageNum:this.pageNum,pageSize:this.pageSize,orderByColumn:'create_time',isAsc:'desc'}).then(obj => {let data = obj.rowsdata.filter(item=>{this.articleList.push({id:item.id,title: item.smallTitle,content: item.bigTitle,createTime: item.createTime})})});}}}
</script>
<style lang="scss" scoped>
.tabSwiper {width: 710rpx;background-color: #ffffff;margin: 20rpx auto;border-radius: 20rpx;box-sizing: border-box;padding: 20rpx;font-size: 28rpx;.top {display: flex;justify-content: space-between;.left {display: flex;align-items: center;.title {margin: 0 10rpx;font-size: 32rpx;font-weight: bold;}}.right {color: $u-tips-color;}}.item {display: flex;margin: 20rpx 0 0;.left {margin-right: 20rpx;image {width: 200rpx;height: 200rpx;border-radius: 10rpx;}}.content {.title {font-size: 28rpx;line-height: 50rpx;}}.right {margin-left: 10rpx;padding-top: 20rpx;text-align: right;}}}.wrap {display: flex;flex-direction: column;height: calc(100vh - var(--window-top));width: 100%;}
</style>

五、詳情頁面

/pages/article/content.vue 添加詳情頁面的vue文件

<template><view><u-navbar :is-back="true" :title="title" :border-bottom="false"></u-navbar><view class="u-content"><u-parse :html="content":autosetTitle="true":show-with-animation="true":selectable="true"></u-parse></view></view>
</template><script>export default {data() {return {title:'文章詳情',content: ``}},onLoad(option) {let id = option.idlet url = "/api/cmsApi/getArticle/"+id;this.$u.get(url).then(res => {this.title = res.data.smallTitlethis.content = res.data.articleContent});},}
</script><style>page{background-color: #FFFFFF;}
</style>
<style lang="scss" scoped>.u-content{margin:0 10rpx;padding: 24rpx;font-size: 34rpx;color: $u-main-color;line-height: 1.8;white-space: pre-wrap !important;}
</style>

在pages.json添加文章詳情頁的的路由

{"pages": [// pages 設置頁面路徑及窗口表現//pages數組中第一項表示應用啟動頁,參考:https://uniapp.dcloud.io/collocation/pages{// pages節點的第一項為應用入口頁(即首頁)"path": "pages/index/index","style": {"navigationStyle": "custom" ,// 導航欄樣式:取消原生系統導航欄"navigationBarTitleText": "首頁", // 導航欄標題文字"enablePullDownRefresh": true,  // 下拉刷新"app-plus": {// 編譯到App平臺的特定樣式"pullToRefresh": {// 下拉刷新小圈圈樣式"support": true,"color": "#2979ff", //小圈圈的顏色"style": "circle" //小圈圈的樣式}}}},{"path" : "pages/article/article","style" : {"navigationStyle": "custom" ,"navigationBarTitleText" : "文章","enablePullDownRefresh" : true}},{"path" : "pages/article/content","style" : {"navigationStyle": "custom" ,"navigationBarTitleText" : "文章詳情","enablePullDownRefresh" : true}}]
}

詳情頁效果如下
在這里插入圖片描述

參考資料

uni-app官網

在此感謝@Ann_0207的技術支持!

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/18595.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/18595.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/18595.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

如何關閉MySQL凌晨12點自動彈窗?

要關閉 MySQL 在凌晨 12 點自動彈窗的行為&#xff0c;首先需要確定彈窗的具體原因。 打開“任務計劃程序”&#xff1a; 按 Win R&#xff0c;輸入 taskschd.msc&#xff0c;然后按 Enter。 在左側導航欄中&#xff0c;選擇“任務計劃程序庫”。 查找與 MySQL 相關的任務&…

vite構建build選項配置(2024-05-29)

build.target? 類型&#xff1a; string | string[]默認&#xff1a; modules相關內容&#xff1a; 瀏覽器兼容性 設置最終構建的瀏覽器兼容目標。默認值是一個 Vite 特有的值&#xff1a;modules&#xff0c;這是指 支持原生 ES 模塊、原生 ESM 動態導入 和 import.meta 的…

軟件構造復習的一些經驗筆記

軟件構造復習的一些經驗筆記 術語解釋 LSP原則&#xff08;里氏替換原則&#xff09; 什么是LSP原則&#xff0c;就是A類繼承B類&#xff0c;A類應該比B類的spec&#xff08;規約&#xff09;更強 換句話說&#xff1a;你爹會做魚香肉絲&#xff0c;你爹的手藝遺傳給了你&a…

基于springboot實現醫療掛號管理系統項目【項目源碼+論文說明】

基于springboot實現醫療掛號管理系統演示 摘要 在如今社會上&#xff0c;關于信息上面的處理&#xff0c;沒有任何一個企業或者個人會忽視&#xff0c;如何讓信息急速傳遞&#xff0c;并且歸檔儲存查詢&#xff0c;采用之前的紙張記錄模式已經不符合當前使用要求了。所以&…

JAVA -- 邏輯控制詳解

JAVA邏輯控制詳解 1.順序結構 按照代碼書寫的順序一行一行執行 System.out.println("123");//123 System.out.println("456");//456 System.out.println("789");//7892.分支結構 if 語句 switch 語句 2.1 if 語句 語法格式1(單分支) //if(布…

安全閥檢測周期:確定因素與操作流程詳解

在工業生產中&#xff0c;安全閥扮演著至關重要的角色&#xff0c;其性能的穩定性和準確性直接關系到設備和系統的安全。為確保安全閥的正常運行和事故防范&#xff0c;對其進行定期檢測顯得尤為關鍵。 接下來&#xff0c;佰德將深入探討安全閥檢測周期相關的內容&#xff0c;…

HTML靜態網頁成品作業(HTML+CSS)——家鄉芷江侗族自治縣介紹網頁(1個頁面)

&#x1f389;不定期分享源碼&#xff0c;關注不丟失哦 文章目錄 一、作品介紹二、作品演示三、代碼目錄四、網站代碼HTML部分代碼 五、源碼獲取 一、作品介紹 &#x1f3f7;?本套采用HTMLCSS&#xff0c;未使用Javacsript代碼&#xff0c;共有1個頁面。 二、作品演示 三、代…

【ROS機器人學習】--------1ROS工作空間和功能包創建

虛擬機工具和鏡像鏈接: https://pan.baidu.com/s/1HDmpbMESiUA2nj3qFVyFcw?pwd8686 提取碼: 8686 ROS工作空間是一個用于組織和管理ROS&#xff08;機器人操作系統&#xff09;包的目錄結構&#xff0c;它通常包含多個子目錄&#xff0c;用于存放源碼、構建文件和安裝文件。工…

香橙派OrangePI AiPro測評

實物 為AI而生 打開盒子 截圖電源開機進入 作為一個AI產品,必須有一個人機交互的界面才行。大家都在跑算法,于是我就開始進行整理著手整理搭建Qt的環境。 1、下載源碼 wget https://download.qt.io/archive/qt/5.12/5.12.12/single/qt-everywhere-src-5.12.12.tar.xz待…

RDP方式連接服務器上傳文件方法

隨筆 目錄 1. RDP 連接服務器 2. 為避免rdp 訪問界面文字不清晰 3. 本地上傳文件到服務器 1. RDP 連接服務器 # mstsc 連接服務器step1: 輸入mstscstep2: 輸入 IP, username, passwd 2. 為避免rdp 訪問界面文字不清晰 解決方法&#xff1a; 3. 本地上傳文件到服務器 step…

關于C++的特殊類定制

特殊類定制 在C中&#xff0c;一些特殊性質的類如何設計 類禁止拷貝的對象 C11 使用delete關鍵字賦值給拷貝構造和賦值C98將拷貝構造和賦值聲明在私有里 類只能在堆上創建的對象 將構造函數私有化, 提供一個獲取對象堆上創建對象的公有函數將析構函數私有化, 提供一個釋放…

JavaScript面向對象編程入門:從0到1的奇幻之旅【含代碼示例】

JavaScript面向對象編程入門&#xff1a;從零到英雄的奇幻之旅【含代碼示例】 一、OOP&#xff1a;編程界的哈利波特基本概念類與實例 二、揮舞魔杖&#xff1a;創建類與實例基本語法 三、繼承與封裝&#xff1a;家族的力量繼承封裝 四、實戰與技巧&#xff1a;打造堅固的魔法城…

IT行業的現狀與未來發展趨勢:從云計算到量子計算的技術變革

隨著技術的不斷進步&#xff0c;IT行業已經成為推動全球經濟和社會發展的關鍵力量。從云計算、大數據、人工智能到物聯網、5G通信和區塊鏈&#xff0c;這些技術正在重塑我們的生活和工作方式。本文將深入探討當前IT行業的現狀&#xff0c;并展望未來發展趨勢&#xff0c;旨在為…

vscode當前分支有未提交的修改,但是暫時不想提交,想要切換到另一個分支該怎么辦

當前分支有未提交的修改,但是暫時不想提交,想要切換到另一個分支該怎么辦? 首先,可以將當前修改暫存起來,以便之后恢復 git stash 然后切換到目標分支,例如需求A所在分支 git checkout feat-a-jie 修改完A需求后,需要先切換回之前的分支,例如需求B所在分支 git checkout feat…

免費插件集-illustrator插件-Ai插件-文本對象分行

文章目錄 1.介紹2.安裝3.通過窗口>擴展>知了插件4.功能解釋5.總結 1.介紹 本文介紹一款免費插件&#xff0c;加強illustrator使用人員工作效率&#xff0c;進行文本對象分行。首先從下載網址下載這款插件 https://download.csdn.net/download/m0_67316550/87890501&…

通過安全的云開發環境重新發現 DevOps 的心跳

云開發平臺如何“提升” DevOps 首先&#xff0c;我來簡單介紹一下什么是云開發環境&#xff1a;它通常運行帶有應用程序的 Linux 操作系統&#xff0c;提供預配置的環境&#xff0c;允許進行編碼、編譯和其他類似于本地環境的操作。從實現的角度來看&#xff0c;這樣的環境類…

前端 JS 經典:讀取文件原始內容

前言&#xff1a;有些時候在工程化開發中&#xff0c;我們需要讀取文件里面的原始內容&#xff0c;比如&#xff0c;你有一個文件&#xff0c;后綴名為 .myfile&#xff0c;你需要拿到這個文件里的內容&#xff0c;該怎么處理呢。 在 vue2 中&#xff0c;因為 vue2 使用 vue-c…

【算法】前綴和——尋找數組的中心下標

本節博客是用前綴和算法圖解“尋找數組的中心下標”&#xff0c;有需要借鑒即可。 目錄 1.題目2.題意3.前綴和求解4.示例代碼5.細節6.總結 1.題目 題目鏈接&#xff1a;LINK 2.題意 我們以示例1為例來圖解一下題意&#xff1a; 3.前綴和求解 根據已有經驗&#xff0c;我…

Java 讀取 xml 文件的五種方式

在編寫與 XML 數據交互的現代軟件應用時&#xff0c;有效地讀取和解析 XML 文件是至關重要的。XML&#xff08;可擴展標記語言&#xff09;因其靈活性和自我描述性&#xff0c;已成為數據存儲和傳輸的一種普遍格式。對于 Java 開發者來說&#xff0c;Java 提供了多種工具和庫來…

數據庫索引相關的知識點總結

目錄 1. 索引的概念 2. 索引的作用 3. 索引的類型 4. 索引的缺點 5. 索引的使用場景 6. 索引的設計原則 7. 索引的實現技術 8. 索引的優化技巧&#xff1a; 數據庫表的索引是一個非常重要的概念&#xff0c;它類似于一本書的目錄&#xff0c;可以幫助我們快速找到所需的…