重生如何获得第一桶金 發表於 2020-8-18 09:17:00

手牵手,使用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&nbsp;<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">//&nbsp;软件版本</span><br>Vue.js&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;<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&nbsp;&nbsp;&nbsp;:&nbsp;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&nbsp;:&nbsp;<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&nbsp;&nbsp;&nbsp;:&nbsp;<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>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">//&nbsp;锻炼听力专用</span><br>WeChat&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;<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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">//&nbsp;寻找对象专用</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目录 -&gt; 创建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">&nbsp;*&nbsp;@description:&nbsp;&nbsp;首页伪代码示例<br>&nbsp;*&nbsp;@author:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zhc<br>&nbsp;*&nbsp;@date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2020-08-17&nbsp;22:27:32<br><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">template</span>&gt;</span><br>&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&nbsp;<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>&gt;</span><br>&nbsp;&nbsp;<span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">&lt;!--&nbsp;loading动画&nbsp;--&gt;</span><br>&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">mi-loading</span>&nbsp;<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>&nbsp;<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>&nbsp;<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>&gt;</span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">mi-loading</span>&gt;</span><br>&nbsp;&nbsp;<span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">&lt;!--&nbsp;整个页面使用&lt;scroll-view&gt;标签&nbsp;--&gt;</span><br>&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">scroll-view</span>&gt;</span><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>###&nbsp;大图Logo及搜索&nbsp;--正常编写<br>&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&nbsp;<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>&gt;</span><br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">image</span>&nbsp;<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>&nbsp;<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>&nbsp;<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>&gt;</span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">image</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&nbsp;<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>&gt;</span>请输入关键字搜索<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&gt;</span>&nbsp;&nbsp;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>###&nbsp;轮播图&nbsp;--使用的colorui的组件<br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">swiper</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">swiper-item</span>&nbsp;<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)&nbsp;in&nbsp;swiperList"</span>&nbsp;<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>&nbsp;<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>&nbsp;@<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>&gt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&nbsp;<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>&gt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">image</span>&nbsp;<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>&nbsp;<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>&nbsp;<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>&gt;</span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">image</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">swiper-item</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">swiper</span>&gt;</span><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>###&nbsp;电影列表&nbsp;--写好样式,使用v-for循环添加,使用<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">uni-load-more</span>&gt;</span>标签上拉加载更多<br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&nbsp;<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>&gt;</span>豆瓣高分<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&nbsp;<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>&gt;</span><br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">uni-load-more</span>&nbsp;<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>&nbsp;<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>&nbsp;<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>&gt;</span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">uni-load-more</span>&gt;</span><br>&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">scroll-view</span>&gt;</span><br>&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&gt;</span><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">template</span>&gt;</span><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">script</span>&gt;</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">//&nbsp;onShareAppMessage函数作用是点击右上角分享小程序,可以配置分享的名称及成功或者失败后的回调函数</span><br>onShareAppMessage:&nbsp;<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>)&nbsp;</span>{<br>&nbsp;<span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">var</span>&nbsp;that&nbsp;=&nbsp;<span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">this</span>;<br>&nbsp;<span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">return</span>&nbsp;{<br>&nbsp;&nbsp;<span class="hljs-attr" style="line-height: 26px">title</span>:&nbsp;<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">'老赵的杂货铺'</span>,<br>&nbsp;&nbsp;<span class="hljs-attr" style="line-height: 26px">path</span>:&nbsp;<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">'pages/index/index'</span>&nbsp;,<br>&nbsp;&nbsp;<span class="hljs-attr" style="line-height: 26px">success</span>:&nbsp;<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>)&nbsp;</span>{<br>&nbsp;&nbsp;&nbsp;<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>&nbsp;+&nbsp;<span class="hljs-built_in" style="color: rgba(0, 134, 179, 1); line-height: 26px">JSON</span>.stringify(res));<br>&nbsp;&nbsp;&nbsp;that.shareClick();<br>&nbsp;&nbsp;},<br>&nbsp;&nbsp;<span class="hljs-attr" style="line-height: 26px">fail</span>:&nbsp;<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>)&nbsp;</span>{<br>&nbsp;&nbsp;<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>&nbsp;+&nbsp;<span class="hljs-built_in" style="color: rgba(0, 134, 179, 1); line-height: 26px">JSON</span>.stringify(res));<br>&nbsp;&nbsp;}<br>&nbsp;}<br>}<br><br><span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">//&nbsp;onReachBottom函数作用是页面触底触发的函数,当加载一定数量,提示没有更多了</span><br>onReachBottom:&nbsp;<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>)&nbsp;</span>{&nbsp;<br>&nbsp;<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>&nbsp;<span class="hljs-keyword" style="color: rgba(51, 51, 51, 1); font-weight: bold; line-height: 26px">this</span>.getmorenews()<br>}&nbsp;&nbsp;&nbsp;<br><br><span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">//&nbsp;这里操作了Storage,把首页的图片和标题存储起来,用作详情页的背景图片和标题</span><br>getDate(item)&nbsp;{<br>&nbsp;uni.setStorage({<br>&nbsp;&nbsp;<span class="hljs-attr" style="line-height: 26px">key</span>:&nbsp;<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">'storage_bg'</span>,<br>&nbsp;<span class="hljs-attr" style="line-height: 26px">data</span>:&nbsp;item.images.small,<br>&nbsp;<span class="hljs-attr" style="line-height: 26px">success</span>:&nbsp;<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>)&nbsp;</span>{<br>&nbsp;&nbsp;<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>&nbsp;}<br>&nbsp;})<br>}<br></span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">script</span>&gt;</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目录 -&gt; 创建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">&nbsp;*&nbsp;@description:&nbsp;&nbsp;详情页面伪代码示例<br>&nbsp;*&nbsp;@author:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zhc<br>&nbsp;*&nbsp;@date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2020-08-17&nbsp;22:54:09<br><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">template</span>&gt;</span>&nbsp;&nbsp;<br>###&nbsp;电影大图<br>&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&nbsp;<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>&gt;</span><br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&nbsp;<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>&nbsp;<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:&nbsp;'url('&nbsp;+&nbsp;viewBg&nbsp;+&nbsp;')'}"</span>&gt;</span>&gt;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&gt;</span><br>&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&gt;</span><br><br>&nbsp;&nbsp;<br>###&nbsp;简介、演职员及评论<br>&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">scroll-view</span>&nbsp;<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>&gt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">text</span>&nbsp;<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>&gt;</span>剧情简介:&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">text</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">text</span>&nbsp;<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>&gt;</span>演职员:&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">text</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">text</span>&nbsp;<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>&nbsp;<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>&gt;</span>精选评论<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">text</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">&lt;!--&nbsp;评分标签使用的是uni自带的&lt;uni-rate&gt;&nbsp;--&gt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">uni-rate</span>&gt;</span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">uni-rate</span>&gt;</span><br>&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">scroll-view</span>&gt;</span><br><br>&nbsp;&nbsp;<br>###&nbsp;预告片<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">&lt;!--&nbsp;#ifdef&nbsp;MP-WEIXIN&nbsp;||&nbsp;MP-BAIDU,条件注释语句,让预告片只在微信小程序上显示,因为当时使用uni-app把该项目代码打包成APP时视频出了一些问题,所以加了条件注释,让其只在微信小程序上显示&nbsp;--&gt;</span><br>&nbsp;&nbsp;<span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">&lt;!--&nbsp;#ifdef&nbsp;MP-WEIXIN&nbsp;||&nbsp;MP-BAIDU&nbsp;--&gt;</span><br>&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&nbsp;<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:&nbsp;98%;margin:&nbsp;0&nbsp;auto;"</span>&gt;</span>预告片&nbsp;/&nbsp;剧照<br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">video</span>&nbsp;<span class="hljs-attr" style="color: rgba(0, 128, 128, 1); line-height: 26px">controls</span>&gt;</span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">video</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&gt;</span><br>&nbsp;&nbsp;<span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">&lt;!--&nbsp;#endif&nbsp;--&gt;</span><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">template</span>&gt;</span><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">script</span>&gt;</span><span class="javascript" style="line-height: 26px"><br>&nbsp;&nbsp;<span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">//&nbsp;onLoad是当页面加载完毕执行,在这里读取了首页存储的图片和标题,</span><br>&nbsp;&nbsp;<span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">//&nbsp;我们通过UI图可以发现背景图会随着不同页面而变化,其实背景图就是首页存储的图片</span><br>&nbsp;&nbsp;<span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">//&nbsp;通过CSS属性&nbsp;filter:&nbsp;blur(60rpx),把图片处理成模糊的效果</span><br>&nbsp;&nbsp;onLoad:&nbsp;<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>)&nbsp;</span>{<br>&nbsp;&nbsp;<span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">//&nbsp;获取本地存储的图片</span><br>&nbsp;&nbsp;uni.getStorage({<br>&nbsp;&nbsp;<span class="hljs-attr" style="line-height: 26px">key</span>:&nbsp;<span class="hljs-string" style="color: rgba(221, 17, 68, 1); line-height: 26px">'storage_bg'</span>,<br>&nbsp;&nbsp;<span class="hljs-attr" style="line-height: 26px">success</span>:&nbsp;<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>)&nbsp;</span>{<br>&nbsp;&nbsp;that.viewBg&nbsp;=&nbsp;res.data<br>&nbsp;}<br>&nbsp;});<br>}<br></span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">script</span>&gt;</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> -&gt; 创建<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">&nbsp;*&nbsp;@description:&nbsp;&nbsp;搜索页面伪代码示例<br>&nbsp;*&nbsp;&nbsp;@author:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zhc<br>&nbsp;*&nbsp;@date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2020-08-17&nbsp;23:40:13<br><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">template</span>&gt;</span><br>###&nbsp;搜索框<br>&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&nbsp;<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:&nbsp;#CAF2F2"</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">cu-custom</span>&nbsp;<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>&gt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">input</span>&nbsp;<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>&nbsp;<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>&nbsp;@<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>&gt;</span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">input</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">cu-custom</span>&gt;</span><br>&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&gt;</span><br><br><br>###&nbsp;搜索之后的列表<br>&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">scroll-view</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;<span class="hljs-comment" style="color: rgba(153, 153, 136, 1); font-style: italic; line-height: 26px">&lt;!--&nbsp;电影列表&nbsp;--&gt;</span><br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&nbsp;<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>&gt;</span>搜索结果<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&nbsp;<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>&gt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&nbsp;<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,&nbsp;index)&nbsp;in&nbsp;movieInfo"</span>&nbsp;&gt;</span><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&gt;</span><br>&nbsp;&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">view</span>&gt;</span><br>&nbsp;&nbsp;<span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">scroll-view</span>&gt;</span><br><span class="hljs-tag" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">&lt;/<span class="hljs-name" style="color: rgba(0, 0, 128, 1); font-weight: normal; line-height: 26px">template</span>&gt;</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]
查看完整版本: 手牵手,使用uni-app从零开发一款视频小程序 (系列下 开发实战篇)