Get Local Image Path in Uniapp: Step-by-Step

In uniapp, you can use the uni.getImageInfo() method to get the local image path. Here are the specific steps:

  1. Import the API of uniapp: import uni from ‘uni’
  2. Retrieve image information using the uni.getImageInfo() method by passing the image path as a parameter: uni.getImageInfo({src: ‘local image path’})
  3. In the callback function of the method, you can retrieve the local image path using res.path.

The sample code is shown below:

import uni from 'uni'

uni.getImageInfo({
  src: '本地图片路径',
  success: function(res) {
    console.log(res.path) // 输出本地图片路径
  }
})

It is important to note that the local image path must be relative to the current page, and you can use either relative paths (e.g. ‘../images/test.png’) or absolute paths (e.g. ‘/static/images/test.png’).

bannerAds