>  기사  >  웹 프론트엔드  >  WeChat 애플릿 템플릿 템플릿 참조 예 공유

WeChat 애플릿 템플릿 템플릿 참조 예 공유

小云云
小云云원래의
2018-02-07 14:08:022420검색

이 글은 WeChat 애플릿 보기 템플릿에서 참조한 세부 예제에 대한 관련 정보를 주로 소개합니다. 도움이 필요한 친구들이 참고할 수 있기를 바랍니다.

WeChat 애플릿 보기 템플릿 참조의 자세한 예

WXML은 가져오기 및 포함이라는 두 가지 파일 참조 방법을 제공합니다.

include는 대상 파일을 제외한 전체 코드를 도입할 수 있습니다. 이는 포함 위치

temlate.wxml


<template name="tmp_data" >

   <view class="content">
    <!-- 头像 -->
    <view class="author-date"> 
      <image src="{{item.header_url}}" class="author"></image>
      <text class="date">{{item.date}}{{idx}}</text>
    </view>
    <!-- 标题内容 -->
     <text class="title">{{item.title}}</text>
     <image class="image" src="{{item.image_url}}"></image>
     <text class="article-content">{{item.content}}</text>
    <view >

     <image class="article-images" src="../../images/icon/chat.png"></image>
     <text class="article-text">66</text>

     <image class="article-images" src="../../images/icon/view.png"></image>
     <text class="article-text">88</text>

    </view>


  </view>

</template>

redirect.wxml reference


<import src="template/template.wxml" />

template.js

에 복사하는 것과 같습니다.


var content_for = [
 {
  date: "2020年 10月 9日 ",
  title: "那年夏天",
  header_url: "/images/3.png",
  image_url: "/images/6.jpg",
  content: "天不言自高,地不言自厚,奇迹,是不会在容易的道路上绽放的。人生没有如果,只有后果和结果,过去的不再回来,回来的不再完美。",
 },
 {
  date: "2022年 10月 9日 ",
  title: "夏天",
  header_url: "/images/3.png",
  image_url: "/images/8.jpg",
  content: "人生没有如果,只有后果和结果,过去的不再回来,回来的不再完美。",
 },

]
//输出出口
module.exports={
 templates: content_for
}

redirect.js는


var content_data=require(&#39;../../template/template.js&#39;)
// pages/redirect/redirect.js
Page({

 /**
  * 页面的初始数据
  */
 data: {

 },

 /**
  * 生命周期函数--监听页面加载
  */
 onLoad: function (options) {

   this.setData({
     key: content_data.templates
   });

 }

});

wxml


 <block wx:for="{{key}}" wx:for-item="item" wx:for-index="idx">
     <!-- is就是模板名字name值 -->
     <template is="tmp_data" data="{{item}}" />
   </block>

template.wxss 파일


.title{
 font-size: 34rpx;
 font-weight: 600;
 color:#333;
 margin-bottom: 20px;
}

redirect.wxss 파일을 의미하며 위 스타일을 의미합니다.


@import "template/template.wxss" //使用import定义

swiper{
 width:100%;
 height:500rpx;
}
swiper image{
  width:100%;
 height:500rpx;
}

관련 권장 사항:

Vue .js에서 템플릿 컴파일 문제를 해결하는 방법

template.js 시작을 위한 팁

요소 및 템플릿에서 v-if 지시어 사용에 대한 자세한 설명

위 내용은 WeChat 애플릿 템플릿 템플릿 참조 예 공유의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.