企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# uniapp从接口获取数据 ``` <pre class="calibre15">``` <span class="token"><</span>template<span class="token">></span> <span class="token"><</span>view <span class="token2">class</span><span class="token">=</span><span class="token4">"luobo"</span> style<span class="token">=</span><span class="token4">"margin-top: 30rpx;"</span><span class="token">></span> <span class="token"><</span>swiper <span class="token1">:</span>indicator<span class="token">-</span>dots<span class="token">=</span><span class="token4">"true"</span> <span class="token1">:</span>autoplay<span class="token">=</span><span class="token4">"true"</span> <span class="token1">:</span>interval<span class="token">=</span><span class="token4">"2000"</span> <span class="token1">:</span>duration<span class="token">=</span><span class="token4">"500"</span><span class="token">></span> <span class="token"><</span>swiper<span class="token">-</span>item v<span class="token">-</span><span class="token2">for</span><span class="token">=</span><span class="token4">"(item,index) in bannerList"</span> <span class="token1">:</span>key<span class="token">=</span><span class="token4">"index"</span> <span class="token">></span> <span class="token"><</span>image <span class="token1">:</span>src<span class="token">=</span><span class="token4">"getUrl(item)"</span> mode<span class="token">=</span><span class="token4">"widthFix"</span> style<span class="token">=</span><span class="token4">"width: 100%;"</span><span class="token">></span><span class="token"><</span><span class="token">/</span>image<span class="token">></span> <span class="token"><</span><span class="token">/</span>swiper<span class="token">-</span>item<span class="token">></span> <span class="token"><</span><span class="token">/</span>swiper<span class="token">></span> <span class="token"><</span><span class="token">/</span>view<span class="token">></span> <span class="token"><</span><span class="token">/</span>template<span class="token">></span> <span class="token"><</span>script<span class="token">></span> <span class="token2">export</span> <span class="token2">default</span> <span class="token1">{</span> <span class="token3">data</span><span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> <span class="token2">return</span> <span class="token1">{</span> bannerList<span class="token1">:</span><span class="token1">[</span><span class="token1">]</span> <span class="token1">}</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">,</span> <span class="token3">onReady</span><span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> <span class="token2">this</span><span class="token1">.</span><span class="token3">lunBo</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">,</span> methods<span class="token1">:</span><span class="token1">{</span> <span class="token3">lunBo</span><span class="token1">(</span><span class="token1">)</span><span class="token1">{</span> <span class="token2">var</span> _self <span class="token">=</span> <span class="token2">this</span><span class="token1">;</span> uni<span class="token1">.</span><span class="token3">request</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span><span class="token2">this</span><span class="token1">.</span>$url<span class="token">+</span><span class="token4">'/api/app/lunbopic'</span><span class="token1">,</span> method<span class="token1">:</span><span class="token4">'POST'</span><span class="token1">,</span> success<span class="token1">:</span><span class="token2">function</span><span class="token1">(</span>res<span class="token1">)</span><span class="token1">{</span> <span class="token2">var</span> info <span class="token">=</span> res<span class="token1">.</span>data<span class="token1">.</span>msg<span class="token1">.</span>luoboimages<span class="token1">.</span><span class="token3">split</span><span class="token1">(</span><span class="token4">","</span><span class="token1">)</span><span class="token1">;</span> _self<span class="token1">.</span>bannerList <span class="token">=</span> info<span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">,</span> <span class="token3">getUrl</span><span class="token1">(</span>ico<span class="token1">)</span><span class="token1">{</span> <span class="token2">return</span> <span class="token2">this</span><span class="token1">.</span>$url<span class="token">+</span>ico<span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> <span class="token1">}</span> <span class="token"><</span><span class="token">/</span>script<span class="token">></span> <span class="token"><</span>style lang<span class="token">=</span><span class="token4">"scss"</span><span class="token">></span> <span class="token"><</span><span class="token">/</span>style<span class="token">></span> ``` ```