[uniapp] Use interface data rendering instead of writing static arrays

 Use a for loop to render a row of boxes, and the data is simulated data:

<template>
    <view class="someList" v-for="(item, index) in fiveList">

				<text>{
   
   {item.name}}</text>
                <text>{
   
   {item.image}}</text>			
    </view>
</template>

<script>
    export default{
        data(){
            return{

              	fiveList: [{
						imgs: '/images/new1.png',
						text: '示例1',
							
					},
					{
						imgs: '/images/new2.png',
						text: '示例2',
				
					},
					{
						imgs: '/images/new3.png',
						text: '示例3',
					}

				],
            }
        }
    }

</script>

To call the interface and use real data, you only need an empty array to accept the return parameter res. For example, we need to start rendering data when the page is loaded:


		onShow() {
		

			//主页加载时调用接口获取数据并渲染

			const data = {

                //接口入参
				custom_app_key: 'appKey',
               // session_3rd: getStorage("session"), // 微信信息标识
			}
			GetProject(data).then(res => {

				console.log("成功")
                //赋值数组参数,替换静态数组
				this.fiveList = res

				console.log(res);

			}).catch(res => {

				console.log("失败");

			})

}

Interpolation syntax can still be used, such as { {item.name}} to render.

Guess you like

Origin blog.csdn.net/ONLYSRY/article/details/127754242