手牵手,使用uni-app从零开发一款视频小程序 (系列下 开发实战篇)
<section id="nice" data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="font-size: 16px; color: rgba(0, 0, 0, 1); padding: 0 10px; word-spacing: 0; word-wrap: break-word; text-align: left; line-height: 1.25; font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light; letter-spacing: 2px; background-image: linear-gradient(90deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%), linear-gradient(360deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%); background-size: 20px 20px; background-position: center"><h1 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0; font-weight: bold; color: rgba(0, 0, 0, 1); font-size: 25px"><span class="prefix" style="display: none"></span><span class="content" style="display: inline-block; font-weight: bold; color: rgba(119, 48, 152, 1)">系列文章</span><span class="suffix"></span></h1><ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: rgba(0, 0, 0, 1); font-size: 15px; list-style-type: circle">
<li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgba(1, 1, 1, 1); font-size: 14px; font-weight: normal"><p style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">手牵手,使用uni-app从零开发一款视频小程序 (系列上 准备工作篇)</p>
</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgba(1, 1, 1, 1); font-size: 14px; font-weight: normal"><p style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">手牵手,使用uni-app从零开发一款视频小程序 (系列下 开发实战篇)</p>
</section></li></ul>
<h2 data-tool="mdnice编辑器" style="margin: 20px 10px 0 0; padding: 0; font-weight: bold; color: rgba(0, 0, 0, 1); font-size: 22px; text-align: left"><span class="prefix" style="display: none"></span><span class="content" style="font-size: 18px; font-weight: bold; display: inline-block; padding-left: 10px; border-left: 5px solid rgba(145, 109, 213, 1)">扫码体验,先睹为快</span><span class="suffix"></span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">可以扫描下微信小程序的二维码,体验一下开发完毕的效果:
<img src="https://zhcat.oss-cn-beijing.aliyuncs.com/image_20200817214858.png" alt="" style="max-width: 100%; border-radius: 6px; display: block; margin: 20px auto; object-fit: contain; box-shadow: 2px 4px 7px rgba(153, 153, 153, 1)"></p>
<h2 data-tool="mdnice编辑器" style="margin: 20px 10px 0 0; padding: 0; font-weight: bold; color: rgba(0, 0, 0, 1); font-size: 22px; text-align: left"><span class="prefix" style="display: none"></span><span class="content" style="font-size: 18px; font-weight: bold; display: inline-block; padding-left: 10px; border-left: 5px solid rgba(145, 109, 213, 1)">代码地址:</span><span class="suffix"></span></h2>
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: rgba(0, 0, 0, 1); font-size: 15px; list-style-type: circle">
<li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgba(1, 1, 1, 1); font-size: 14px; font-weight: normal"><p style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">GitHub : https://github.com/Tzlibai/uni-app-video -- Star 100+</p>
</section></li><li><section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgba(1, 1, 1, 1); font-size: 14px; font-weight: normal"><p style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">uni-app插件市场地址: https://ext.dcloud.net.cn/plugin?id=1839 --插件下载量1000+</p>
</section></li></ul>
<h1 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0; font-weight: bold; color: rgba(0, 0, 0, 1); font-size: 25px"><span class="prefix" style="display: none"></span><span class="content" style="display: inline-block; font-weight: bold; color: rgba(119, 48, 152, 1)">前言</span><span class="suffix"></span></h1>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">Hello,又见面了~</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">相信你看到这篇文章的时候已经阅读了上篇文章的开发这个小程序的准备工作,如果你准备好了,那接下来让我们一起开始吧!</p>
<hr data-tool="mdnice编辑器" style="margin: 10px 0; height: 1px; padding: 0; border-top: 2px solid rgba(217, 184, 250, 1); border-right: none; border-bottom: none; border-left: none">
<h1 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0; font-weight: bold; color: rgba(0, 0, 0, 1); font-size: 25px"><span class="prefix" style="display: none"></span><span class="content" style="display: inline-block; font-weight: bold; color: rgba(119, 48, 152, 1)">开发</span><span class="suffix"></span></h1>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px"><code class="hljs" style="overflow-x: auto; padding: 16px; color: rgba(51, 51, 51, 1); background: rgba(248, 248, 248, 1); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0; font-size: 12px; -webkit-overflow-scrolling: touch">本机当前环境:<br><br>操作系统:Windows <span class="hljs-number" style="color: rgba(0, 128, 128, 1); line-height: 26px">10</span><br><br><span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">// 软件版本</span><br>Vue.js : <span class="hljs-number" style="color: rgba(0, 128, 128, 1); line-height: 26px">2.9</span><span class="hljs-number" style="color: rgba(0, 128, 128, 1); line-height: 26px">.6</span><br>Node.js : v12<span class="hljs-number" style="color: rgba(0, 128, 128, 1); line-height: 26px">.13</span><span class="hljs-number" style="color: rgba(0, 128, 128, 1); line-height: 26px">.0</span><br>HBuilderX : <span class="hljs-number" style="color: rgba(0, 128, 128, 1); line-height: 26px">2.7</span><span class="hljs-number" style="color: rgba(0, 128, 128, 1); line-height: 26px">.5</span><span class="hljs-number" style="color: rgba(0, 128, 128, 1); line-height: 26px">.20200519</span><br>QQMusic : <span class="hljs-number" style="color: rgba(0, 128, 128, 1); line-height: 26px">17.77</span><span class="hljs-number" style="color: rgba(0, 128, 128, 1); line-height: 26px">.5338</span><span class="hljs-number" style="color: rgba(0, 128, 128, 1); line-height: 26px">.0714</span> <span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">// 锻炼听力专用</span><br>WeChat : <span class="hljs-number" style="color: rgba(0, 128, 128, 1); line-height: 26px">2.9</span><span class="hljs-number" style="color: rgba(0, 128, 128, 1); line-height: 26px">.5</span><span class="hljs-number" style="color: rgba(0, 128, 128, 1); line-height: 26px">.41</span> <span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">// 寻找对象专用</span><br></code></pre>
<h1 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0; font-weight: bold; color: rgba(0, 0, 0, 1); font-size: 25px"><span class="prefix" style="display: none"></span><span class="content" style="display: inline-block; font-weight: bold; color: rgba(119, 48, 152, 1)">页面开发</span><span class="suffix"></span></h1>
<h2 data-tool="mdnice编辑器" style="margin: 20px 10px 0 0; padding: 0; font-weight: bold; color: rgba(0, 0, 0, 1); font-size: 22px; text-align: left"><span class="prefix" style="display: none"></span><span class="content" style="font-size: 18px; font-weight: bold; display: inline-block; padding-left: 10px; border-left: 5px solid rgba(145, 109, 213, 1)">1 首页的页面开发</span><span class="suffix"></span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">初始工作我们已经完成了,接下来我们进入每个页面的开发。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">首先我们在<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background: none; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgba(145, 109, 213, 1); font-weight: bolder">pages</code>目录下创建index目录 -> 创建index.vue文件
<img src="https://zhcat.oss-cn-beijing.aliyuncs.com/image_20200817221050.png" alt="" style="max-width: 100%; border-radius: 6px; display: block; margin: 20px auto; object-fit: contain; box-shadow: 2px 4px 7px rgba(153, 153, 153, 1)"></p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">创建好文件之后,还需要在pages.json中添加路由:pagesjson文件源码地址:pages.json
<img src="https://zhcat.oss-cn-beijing.aliyuncs.com/image_20200817221131.png" alt="" style="max-width: 100%; border-radius: 6px; display: block; margin: 20px auto; object-fit: contain; box-shadow: 2px 4px 7px rgba(153, 153, 153, 1)"></p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0; color: rgba(0, 0, 0, 1); font-size: 16px; font-weight: bold; text-align: center"><span class="prefix" style="display: none"></span><span class="content" style="border-bottom: 2px solid rgba(216, 156, 246, 1)">1.1 首页的UI图</span><span class="suffix" style="display: none"></span></h3>
<figure data-tool="mdnice编辑器" style="margin: 10px 0; display: flex; flex-direction: column; justify-content: center; align-items: center"><img src="https://zhcat.oss-cn-beijing.aliyuncs.com/image_20200817221312.png" alt="" style="max-width: 100%; border-radius: 6px; display: block; margin: 20px auto; object-fit: contain; box-shadow: 2px 4px 7px rgba(153, 153, 153, 1)"></figure>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0; color: rgba(0, 0, 0, 1); font-size: 16px; font-weight: bold; text-align: center"><span class="prefix" style="display: none"></span><span class="content" style="border-bottom: 2px solid rgba(216, 156, 246, 1)">1.2 核心代码分析</span><span class="suffix" style="display: none"></span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px"><strong style="color: rgba(145, 109, 213, 1); font-weight: bold"><span>「</span>我们可以把该页面分成三个部分:大图Logo及搜索、轮播图、电影列表<span>」</span></strong></p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">页面代码大家可以直接打开首页源码(首页源码地址)复制到你的 index.vue 文件中查看效果,页面代码非常简单,我这边把关键代码分析下。</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px"><code class="hljs" style="overflow-x: auto; padding: 16px; color: rgba(51, 51, 51, 1); background: rgba(248, 248, 248, 1); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0; font-size: 12px; -webkit-overflow-scrolling: touch"> * @description: 首页伪代码示例<br> * @author: zhc<br> * @date: 2020-08-17 22:27:32<br><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">template</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"container"</span>></span><br> <span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px"><!-- loading动画 --></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">mi-loading</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">ref</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"loading"</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">title</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"加载中"</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">:hasMask</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"true"</span>></span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">mi-loading</span>></span><br> <span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px"><!-- 整个页面使用<scroll-view>标签 --></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">scroll-view</span>></span><br><br> <br>### 大图Logo及搜索 --正常编写<br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"topBar"</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">image</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">src</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"~@/static/img/banner.png"</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">mode</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"widthFix"</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"response"</span>></span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">image</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"search-t"</span>></span>请输入关键字搜索<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>></span> <br><br> <br>### 轮播图 --使用的colorui的组件<br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">swiper</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">swiper-item</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">v-for</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"(item,index) in swiperList"</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">:key</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"index"</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">:class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"cardCur==index?'cur':''"</span> @<span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">click</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"getBanner(item)"</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"swiper-item"</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">image</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">:src</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"item.url"</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">mode</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"aspectFill"</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">v-if</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"item.type=='image'"</span>></span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">image</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">swiper-item</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">swiper</span>></span><br><br> <br>### 电影列表 --写好样式,使用v-for循环添加,使用<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">uni-load-more</span>></span>标签上拉加载更多<br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"movieH"</span>></span>豆瓣高分<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"movieBox"</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">uni-load-more</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">:status</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"listStatus"</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">:contentText</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"contentText"</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">v-if</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"loadStatu"</span>></span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">uni-load-more</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">scroll-view</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>></span><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">template</span>></span><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">script</span>></span><span class="javascript" style="line-height: 26px"><br><span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">// onShareAppMessage函数作用是点击右上角分享小程序,可以配置分享的名称及成功或者失败后的回调函数</span><br>onShareAppMessage: <span class="hljs-function" style="line-height: 26px"><span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">function</span>(<span class="hljs-params" style="line-height: 26px">res</span>) </span>{<br> <span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">var</span> that = <span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">this</span>;<br> <span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">return</span> {<br> <span class="hljs-attr" style="line-height: 26px">title</span>: <span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">'老赵的杂货铺'</span>,<br> <span class="hljs-attr" style="line-height: 26px">path</span>: <span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">'pages/index/index'</span> ,<br> <span class="hljs-attr" style="line-height: 26px">success</span>: <span class="hljs-function" style="line-height: 26px"><span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">function</span>(<span class="hljs-params" style="line-height: 26px">res</span>) </span>{<br> <span class="hljs-built_in" style="color: rgba(0, 134, 179, 1); line-height: 26px">console</span>.log(<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"转发成功:"</span> + <span class="hljs-built_in" style="color: rgba(0, 134, 179, 1); line-height: 26px">JSON</span>.stringify(res));<br> that.shareClick();<br> },<br> <span class="hljs-attr" style="line-height: 26px">fail</span>: <span class="hljs-function" style="line-height: 26px"><span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">function</span>(<span class="hljs-params" style="line-height: 26px">res</span>) </span>{<br> <span class="hljs-built_in" style="color: rgba(0, 134, 179, 1); line-height: 26px">console</span>.log(<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"转发失败:"</span> + <span class="hljs-built_in" style="color: rgba(0, 134, 179, 1); line-height: 26px">JSON</span>.stringify(res));<br> }<br> }<br>}<br><br><span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">// onReachBottom函数作用是页面触底触发的函数,当加载一定数量,提示没有更多了</span><br>onReachBottom: <span class="hljs-function" style="line-height: 26px"><span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">function</span>(<span class="hljs-params" style="line-height: 26px"></span>) </span>{ <br> <span class="hljs-built_in" style="color: rgba(0, 134, 179, 1); line-height: 26px">console</span>.log(<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">'触底’'</span>)<br> <span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">this</span>.getmorenews()<br>} <br><br><span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">// 这里操作了Storage,把首页的图片和标题存储起来,用作详情页的背景图片和标题</span><br>getDate(item) {<br> uni.setStorage({<br> <span class="hljs-attr" style="line-height: 26px">key</span>: <span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">'storage_bg'</span>,<br> <span class="hljs-attr" style="line-height: 26px">data</span>: item.images.small,<br> <span class="hljs-attr" style="line-height: 26px">success</span>: <span class="hljs-function" style="line-height: 26px"><span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">function</span>(<span class="hljs-params" style="line-height: 26px"></span>) </span>{<br> <span class="hljs-built_in" style="color: rgba(0, 134, 179, 1); line-height: 26px">console</span>.log(<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">'item.images.small'</span>);<br> }<br> })<br>}<br></span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">script</span>></span><br></code></pre>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0; color: rgba(0, 0, 0, 1); font-size: 16px; font-weight: bold; text-align: center"><span class="prefix" style="display: none"></span><span class="content" style="border-bottom: 2px solid rgba(216, 156, 246, 1)">1.3 总结</span><span class="suffix" style="display: none"></span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">整个页面加上css代码总共400行左右,其实还是比较简单,如果你在过程中遇到了问题,可以在下面评论处留言,我会第一时间回复你的疑问~</p>
<h2 data-tool="mdnice编辑器" style="margin: 20px 10px 0 0; padding: 0; font-weight: bold; color: rgba(0, 0, 0, 1); font-size: 22px; text-align: left"><span class="prefix" style="display: none"></span><span class="content" style="font-size: 18px; font-weight: bold; display: inline-block; padding-left: 10px; border-left: 5px solid rgba(145, 109, 213, 1)">2 详情页面开发</span><span class="suffix"></span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">首页我们已经完成了,接下来我们进入列表详情页面的开发。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">首先我们在<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background: none; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgba(145, 109, 213, 1); font-weight: bolder">pages</code>目录下创建detail目录 -> 创建index.vue文件
<img src="https://zhcat.oss-cn-beijing.aliyuncs.com/image_20200817223854.png" alt="" style="max-width: 100%; border-radius: 6px; display: block; margin: 20px auto; object-fit: contain; box-shadow: 2px 4px 7px rgba(153, 153, 153, 1)"></p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">创建好文件之后,还需要在pages.json中添加<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background: none; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgba(145, 109, 213, 1); font-weight: bolder">detail</code>路由:pagesjson文件源码地址:pages.json
<img src="https://zhcat.oss-cn-beijing.aliyuncs.com/image_20200817224128.png" alt="" style="max-width: 100%; border-radius: 6px; display: block; margin: 20px auto; object-fit: contain; box-shadow: 2px 4px 7px rgba(153, 153, 153, 1)"></p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0; color: rgba(0, 0, 0, 1); font-size: 16px; font-weight: bold; text-align: center"><span class="prefix" style="display: none"></span><span class="content" style="border-bottom: 2px solid rgba(216, 156, 246, 1)">2.1 详情的UI图</span><span class="suffix" style="display: none"></span></h3>
<figure data-tool="mdnice编辑器" style="margin: 10px 0; display: flex; flex-direction: column; justify-content: center; align-items: center"><img src="https://zhcat.oss-cn-beijing.aliyuncs.com/image_20200817224510.png" alt="" style="max-width: 100%; border-radius: 6px; display: block; margin: 20px auto; object-fit: contain; box-shadow: 2px 4px 7px rgba(153, 153, 153, 1)"></figure>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0; color: rgba(0, 0, 0, 1); font-size: 16px; font-weight: bold; text-align: center"><span class="prefix" style="display: none"></span><span class="content" style="border-bottom: 2px solid rgba(216, 156, 246, 1)">2.2 核心代码分析</span><span class="suffix" style="display: none"></span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px"><strong style="color: rgba(145, 109, 213, 1); font-weight: bold"><span>「</span>我们依旧可以把该页面分成三个部分:电影大图、简介、演职员及评论、预告片<span>」</span></strong></p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">详情页面代码大家可以直接打开详情页的源码(详情页源码地址)复制到你的 /detail/index.vue 文件中查看效果,页面代码也是非常简单,我照例把关键代码分析下。</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px"><code class="hljs" style="overflow-x: auto; padding: 16px; color: rgba(51, 51, 51, 1); background: rgba(248, 248, 248, 1); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0; font-size: 12px; -webkit-overflow-scrolling: touch"> * @description: 详情页面伪代码示例<br> * @author: zhc<br> * @date: 2020-08-17 22:54:09<br><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">template</span>></span> <br>### 电影大图<br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"detailBgMax"</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"detailBg"</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">:style</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"{backgroundImage: 'url(' + viewBg + ')'}"</span>></span>><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>></span><br><br> <br>### 简介、演职员及评论<br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">scroll-view</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"scrollBox"</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">text</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">v-if</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"summarStatu"</span>></span>剧情简介: <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">text</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">text</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">v-if</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"summarStatu"</span>></span>演职员: <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">text</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">text</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"hTitle"</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">v-if</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"summarStatu"</span>></span>精选评论<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">text</span>></span><br> <span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px"><!-- 评分标签使用的是uni自带的<uni-rate> --></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">uni-rate</span>></span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">uni-rate</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">scroll-view</span>></span><br><br> <br>### 预告片<br> <span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px"><!-- #ifdef MP-WEIXIN || MP-BAIDU,条件注释语句,让预告片只在微信小程序上显示,因为当时使用uni-app把该项目代码打包成APP时视频出了一些问题,所以加了条件注释,让其只在微信小程序上显示 --></span><br> <span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px"><!-- #ifdef MP-WEIXIN || MP-BAIDU --></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">style</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"width: 98%;margin: 0 auto;"</span>></span>预告片 / 剧照<br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">video</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">controls</span>></span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">video</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>></span><br> <span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px"><!-- #endif --></span><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">template</span>></span><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">script</span>></span><span class="javascript" style="line-height: 26px"><br> <span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">// onLoad是当页面加载完毕执行,在这里读取了首页存储的图片和标题,</span><br> <span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">// 我们通过UI图可以发现背景图会随着不同页面而变化,其实背景图就是首页存储的图片</span><br> <span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">// 通过CSS属性 filter: blur(60rpx),把图片处理成模糊的效果</span><br> onLoad: <span class="hljs-function" style="line-height: 26px"><span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">function</span>(<span class="hljs-params" style="line-height: 26px">option</span>) </span>{<br> <span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">// 获取本地存储的图片</span><br> uni.getStorage({<br> <span class="hljs-attr" style="line-height: 26px">key</span>: <span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">'storage_bg'</span>,<br> <span class="hljs-attr" style="line-height: 26px">success</span>: <span class="hljs-function" style="line-height: 26px"><span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">function</span>(<span class="hljs-params" style="line-height: 26px">res</span>) </span>{<br> that.viewBg = res.data<br> }<br> });<br>}<br></span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">script</span>></span><br></code></pre>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0; color: rgba(0, 0, 0, 1); font-size: 16px; font-weight: bold; text-align: center"><span class="prefix" style="display: none"></span><span class="content" style="border-bottom: 2px solid rgba(216, 156, 246, 1)">2.3 总结</span><span class="suffix" style="display: none"></span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">这里强行总结一下,如果你在这里遇到了问题,可以在评论处留言,除了夜里睡觉时间,我会第一时间回复你的疑问~~</p>
<h2 data-tool="mdnice编辑器" style="margin: 20px 10px 0 0; padding: 0; font-weight: bold; color: rgba(0, 0, 0, 1); font-size: 22px; text-align: left"><span class="prefix" style="display: none"></span><span class="content" style="font-size: 18px; font-weight: bold; display: inline-block; padding-left: 10px; border-left: 5px solid rgba(145, 109, 213, 1)">3 搜索页面</span><span class="suffix"></span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">首页、详情我们已经完成了,是不是比你想象中的简单,接下来我们进入搜索页面的开发。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">首先我们在<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background: none; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgba(145, 109, 213, 1); font-weight: bolder">pages</code>目录下创建<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background: none; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgba(145, 109, 213, 1); font-weight: bolder">search目录</code> -> 创建<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background: none; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgba(145, 109, 213, 1); font-weight: bolder">index.vue文件</code>
<img src="https://zhcat.oss-cn-beijing.aliyuncs.com/image_20200817232239.png" alt="" style="max-width: 100%; border-radius: 6px; display: block; margin: 20px auto; object-fit: contain; box-shadow: 2px 4px 7px rgba(153, 153, 153, 1)"></p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">老规矩,创建好文件之后,还需要在pages.json中添加<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background: none; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgba(145, 109, 213, 1); font-weight: bolder">search</code>路由:pagesjson文件源码地址:pages.json
<img src="https://zhcat.oss-cn-beijing.aliyuncs.com/image_20200817232322.png" alt="" style="max-width: 100%; border-radius: 6px; display: block; margin: 20px auto; object-fit: contain; box-shadow: 2px 4px 7px rgba(153, 153, 153, 1)"></p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0; color: rgba(0, 0, 0, 1); font-size: 16px; font-weight: bold; text-align: center"><span class="prefix" style="display: none"></span><span class="content" style="border-bottom: 2px solid rgba(216, 156, 246, 1)">3.1 搜索的UI图</span><span class="suffix" style="display: none"></span></h3>
<figure data-tool="mdnice编辑器" style="margin: 10px 0; display: flex; flex-direction: column; justify-content: center; align-items: center"><img src="https://zhcat.oss-cn-beijing.aliyuncs.com/image_20200817232545.png" alt="" style="max-width: 100%; border-radius: 6px; display: block; margin: 20px auto; object-fit: contain; box-shadow: 2px 4px 7px rgba(153, 153, 153, 1)"></figure>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0; color: rgba(0, 0, 0, 1); font-size: 16px; font-weight: bold; text-align: center"><span class="prefix" style="display: none"></span><span class="content" style="border-bottom: 2px solid rgba(216, 156, 246, 1)">3.2 核心代码分析</span><span class="suffix" style="display: none"></span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px"><strong style="color: rgba(145, 109, 213, 1); font-weight: bold"><span>「</span>我们依旧可以把该页面分成...,分成两个模块,搜索框、下方搜索之后的列表<span>」</span></strong></p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">
搜索页面代码大家如上节一样可以直接打开搜索页面的源码(搜索页面源码地址)复制到你的 /search/index.vue 文件中查看效果,页面代码也是非常简单,我依旧、照例、还是把关键代码分析下。</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px"><code class="hljs" style="overflow-x: auto; padding: 16px; color: rgba(51, 51, 51, 1); background: rgba(248, 248, 248, 1); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0; font-size: 12px; -webkit-overflow-scrolling: touch"> * @description: 搜索页面伪代码示例<br> * @author: zhc<br> * @date: 2020-08-17 23:40:13<br><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">template</span>></span><br>### 搜索框<br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">style</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"background-color: #CAF2F2"</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">cu-custom</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">:isBack</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"true"</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">input</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"search-t"</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">placeholder</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"请输入关键字搜索"</span> @<span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">input</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"messagesearch"</span>></span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">input</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">cu-custom</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>></span><br><br><br>### 搜索之后的列表<br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">scroll-view</span>></span><br> <span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px"><!-- 电影列表 --></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"movieH"</span>></span>搜索结果<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">class</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"movieBox"</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"><<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span> <span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">v-for</span>=<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">"(item, index) in movieInfo"</span> ></span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>></span><br> <span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">scroll-view</span>></span><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px"></<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">template</span>></span><br></code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">搜索页面的一些逻辑其实和首页的基本相同,这里就不做过多赘述。</p>
<h1 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0; font-weight: bold; color: rgba(0, 0, 0, 1); font-size: 25px"><span class="prefix" style="display: none"></span><span class="content" style="display: inline-block; font-weight: bold; color: rgba(119, 48, 152, 1)">后记</span><span class="suffix"></span></h1>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">现在已经一点了,越写越佩服一直在坚持写博客的大佬们,我们打开阅读一篇文章可能只需要几分钟,但是编写一篇优质的博客可能需要几天,向所有的博主致敬~</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">这个项目三个页面下来代码不到2000行,阅读上手还是比较容易,如果在过程中遇到问题或是编写错误,可以在下方评论处留言,我会第一时间回复.</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">到这里<strong style="color: rgba(145, 109, 213, 1); font-weight: bold"><span>「</span>手牵手写小程序<span>」</span></strong>的旅程就该结束了,期待下次再见!</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: rgba(0, 0, 0, 1); margin: 10px 0; letter-spacing: 2px; font-size: 14px; word-spacing: 2px">谢谢你愿意花时间阅读这篇文章,希望可以对你有所帮助,早点休息,别熬太晚梦会短~</p>
</section><br><br>
来源:https://www.cnblogs.com/zhaohongcheng/p/13521526.html
頁:
[1]