最近发现有很多用户在开发小程序的时候,经常会问题一个问题,小程序大都能够实现点击文字跳转,对于图片跳转要怎么实现呢,相信有开发过小程序经验的应该都遇到过这个问题,今天厦门在乎科技为大家带来小程序实现图片跳转方法,一起来了解一下吧。

微信小程序点击图片跳转:
1、在微信开发者工具中,打开app.json文件,在pages数组中增加show.wxml页面相关文件的代码,代码如下:
{
"pages":[
"pages/index/index",
"pages/show/show",
"pages/logs/logs"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#ccc",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle":"black"
}
}
2、在index.wxml文件中,在类为usermotto的view组件中添加绑定属性catchtap='enterShow',代码如下:
<!--index.wxml-->
<view class="container">
<view class="userinfo">
<button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
<block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</block>
</view>
<view class="usermotto" catchtap='enterShow'>
<text class="user-motto">{{motto}}</text>
</view>
</view>

3、在index.js文件中,将data中motto的值改为“点击进入”。编写实现跳转的自定义函数enterShow,代码如下:
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
motto: '点击进入',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
//事件处理函数
enterShow:function(){
wx.navigateTo({
url: '../show/show',
})
4、 在show.wxml中,输入跳转后页面显示的信息,代码如下:
<view>
<text>这是跳转后的页面</text>
<view>

5、在index.xwml中点击测试
说明:在上面的页面跳转自定义函数enterShow中,也可以使用wx.redirectTo实现跳转。两者的区别:redirectTo将关闭当前页面,跳转到指定页面,页面左上角没有返回的箭头按钮;而navigateTo将保留页面,跳转到指定页面,页面左上角有返回的箭头按钮。
以上就是今天为大家带来的“微信小程序点击图片跳转 小程序实现图片跳转方法”全部内容,通过这几年的不断调整,小程序的功能正在慢慢的完善,但是开发难度也在不断增加,所以需要我们仔细研究,想要了解更多关于小程序开发的内容,欢迎关注厦门在乎科技-专注小程序、app、网站开发。