title: Taro.setPageInfo(option)

sidebar_label: setPageInfo

Baidu Smart-Program can access Baidu Search and Baidu App. setPageInfo is responsible for setting up all kinds of basic page information for the mini program, including title, keywords, page description, as well as image information and video information.By setting page information for the mini program, the developer can help the mini program to be displayed and distributed more effectively in search engines and information flow.

Reference

Type

  1. (option: Option) => void

Parameters

Option

Property Type Required Description
title string Yes Page title
keywords string Yes Page keywords
description string Yes Page description
releaseDate string No Original release time (year-month-day hour:minute:second with leading zeros)
articleTitle string No Article (content) title.
image string | string[] No Image online address for cover display after infomercial placement, maximum 3 images, single image maximum 2M;
Recommended size of cover image: height>=210px & width>=375px;
Minimum size: height>=146px & width>=218px.
For multiple images, use an array.
video Video No Video information. Representation of multiple videos in an array
visit Visit No Information for visit
likes string No The number of likes, if the page is not counted is empty.
comments string No The number of comments, if the page is not counted is empty.
collects string No The number of collects, if the page is not counted is empty.
shares string No The number of shares, if the page is not counted is empty.
followers string No The number of followers, if the page is not counted is empty.
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

Video

Property Type Description
url string Address of the video
duration string Duration of the video (in seconds)
image string Cover image of the video

Visit

Property Type Required Description
pv string No Page views
uv string No Unique views
sessionDuration string No Length of stay per user on the page, in seconds.

Sample Code

  1. Taro.setPageInfo({
  2. title: 'title',
  3. keywords: 'keywords',
  4. description: 'description',
  5. articleTitle: 'articleTitle',
  6. releaseDate: '2019-01-02 12:01:30',
  7. image: [
  8. 'https://c.hiphotos.baidu.com/forum/w%3D480/sign=73c62dda83b1cb133e693d1bed5456da/f33725109313b07e8dee163d02d7912396dd8cfe.jpg',
  9. 'https://hiphotos.baidu.com/fex/%70%69%63/item/43a7d933c895d143e7b745607ef082025baf07ab.jpg'
  10. ],
  11. video: [{
  12. url: 'https://www.baidu.com/mx/v12.mp4',
  13. duration: '100',
  14. image: 'https://smartprogram.baidu.com/docs/img/image-scaleToFill.png'
  15. }],
  16. visit: {
  17. pv: '1000',
  18. uv: '100',
  19. sessionDuration: '130'
  20. },
  21. likes: '75',
  22. comments: '13',
  23. collects: '23',
  24. shares: '8',
  25. followers: '35',
  26. success: res => {
  27. console.log('setPageInfo success');
  28. },
  29. fail: err => {
  30. console.log('setPageInfo fail', err);
  31. }
  32. })

API Support

API WeChat Mini-Program Baidu Smart-Program H5 React Native
Taro.setPageInfo ✔️