在此之前续膳,想要從小程序里面跳轉(zhuǎn)一個鏈接,要使用web-view
才可以兰粉,而且個人
<web-view src="xxxxxxx"></web-view>
一行就ok.
但是有一定的局限性
1:前段時間,微信正式宣布為方便開發(fā)者靈活配置小程序顶瞳,小程序現(xiàn)開放內(nèi)嵌 Web 頁面能力玖姑,但這個開放的能力也具有一定的局限性,小程序如果想要內(nèi)嵌網(wǎng)頁慨菱,那域名只能是自己公司的焰络,對這個網(wǎng)站擁有控制權(quán)才可以。
2:如果:“ 個人類型與海外類型的小程序暫不支持使用符喝∩帘耍”
你需要先配置業(yè)務(wù)域名,但是個人類型的小程序协饲,還不支持這個功能畏腕。
隨著小程序不斷的發(fā)展,現(xiàn)在個人的小程序也開放了很多功能了茉稠,個人小程序直接打開公眾號鏈接描馅。在群里看到的一款小程序,點擊可以直接閱讀文章了战惊,所以琢磨了一下,寫了一些源碼。
主要代碼:
<web-view src="https://mp.weixin.qq.com/s?__biz=MzI2ODUxMzg4Nw==&mid=2247485016&idx=1&sn=e5f60600ea30f669264ddcf5db4fb080&chksm=eaef2168dd98a87ead60eed0f24e799c1befbfe95e341231216af72315c33a56839f92e69ef9&token=29762947&lang=zh_CN#rd"></web-view>
為了達(dá)到效果吞获,更加具體的demo
效果如下
github地址:https://github.com/wangxiaoting666/weixinlink
weixin.wxml
<navigator url="/pages/search/search" hover-class="changestyle">
<view class="view-search">
<input class="input" placeholder-class="input-placeholder" placeholder="輸入文章和鏈接" bindinput="bindSearchInput" />
<image class="button" src="/images/search.png" bindtap="tapSearch" />
</view>
</navigator>
<view class="container">
<view wx:for="{{cardTeams}}" wx:key="{{cardTeam.viewid}}" wx:for-item="cardTeam" class="item" bindtap="bindViewTap">
<image class="img" src="{{cardTeam.imgsrc}}" mode="scaleToFill"></image>
<view class="number-wrapper">
<text class="name">{{cardTeam.name}}</text>
<view class="count-wrapper">
<text class="count">{{cardTeam.count}}</text>
</view>
</view>
</view>
</view>
weixin.wxss
.container {
padding-top: 0;
}
.item {
width: 100%;
height: 220rpx;
position: relative;
display: flex;
margin: 10rpx 10rpx;
border-bottom: 1px solid rgb(197, 199, 199);
}
.item:first-child {
margin-top: 0;
}
.item .remove {
width: 60px;
height: 100%;
background-color: red;
position: absolute;
top: 0;
right: -60px;
display: flex;
justify-content: center;
align-items: center;
}
.item .number-wrapper {
height: 100%;
padding-top: 40rpx;
flex-direction: column;
justify-content: space-between;
}
.item .ok {
width: 60px;
height: 100%;
padding-right: 20rpx;
display: flex;
justify-content: center;
align-items: center;
background-color: #98f5ff;
}
.item .img {
width: 150rpx;
height: 150rpx;
padding: 20rpx;
}
.number-wrapper .name {
margin: 10rpx 10rpx 10rpx 10rpx;
font-size: 39rpx;
overflow: hidden;
}
.number-wrapper .count-wrapper {
display: flex;
align-items: center;
margin-left: 10rpx;
font-size: 25rpx;
}
.number-wrapper .count-wrapper .decrease-btn {
font-size: 30rpx;
}
.number-wrapper .count-wrapper .increase-btn {
font-size: 30rpx;
}
.number-wrapper .count-wrapper .count {
margin: 0 1rpx 0 1rpx;
font-size: 30rpx;
}
.number-wrapper .price-wrapper .people {
margin-left: 250rpx;
font-size: 30rpx;
}
/* 搜索框樣式 */
.view-search {
display: flex;
flex-direction: row;
height: 70rpx;
margin: 20rpx;
padding: 5rpx;
border: 1px #e4e2e2 solid;
border-width: thin;
align-items: center;
}
.input {
flex: 1;
height: 60rpx;
}
.input-placeholder {
color: #999;
}
.button {
width: 60rpx;
height: 60rpx;
}
weixin.js
//index.js
//獲取應(yīng)用實例
var app = getApp();
var cardTeams;
Page({
data: {
cardTeams: [{
"viewid": "1",
"imgsrc": "../../images/win/1.jpg",
"price": "¥1245",
"count": "一個40歲老碼農(nóng)的總結(jié)况凉,",
"name": "一個40歲老碼農(nóng)的總結(jié),奮斗",
}, {
"viewid": "2",
"imgsrc": "../../images/win/2.jpg",
"price": "¥2345",
"count": "小公司打雜三年各拷,意外拿到",
"name": "小公司打雜三年刁绒,意外拿到美",
}, {
"viewid": "3",
"imgsrc": "../../images/win/3.jpg",
"price": "¥2345",
"count": "作為一個有追求的前端程序媛作",
"name": "作為一個有追求的前端程序媛",
}, {
"viewid": "4",
"imgsrc": "../../images/win/4.jpg",
"price": "¥2345",
"count": "女程序媛面試總結(jié):我",
"name": "女程序媛面試總結(jié):我是這",
},
{
"viewid": "5",
"imgsrc": "../../images/win/5.jpg",
"price": "¥2345",
"count": "前端工作那些年,怎么避烤黍?",
"name": "前端工作那些年知市,怎么避免",
}
]
},
//事件處理函數(shù)
bindViewTap: function() {
wx.navigateTo({
url: '../weixinlink/weixinlink'
})
},
onLoad: function() {
console.log('onLoad:' + app.globalData.domain)
}
})
文章界面
weixinlink.wxml
<web-view src="https://mp.weixin.qq.com/s?__biz=MzI2ODUxMzg4Nw==&mid=2247485427&idx=1&sn=ebfb8851c6cbb0d40c93f8ecbda83687&chksm=eaef20c3dd98a9d5a19f5ad195888c603c8c819021bab602d11f9aa757b66475d39d23f664c4&token=1408526571&lang=zh_CN#rd"></web-view>
注意:
小程序要和公眾號關(guān)聯(lián),鏈接才可以打開速蕊。
原文作者:祈澈姑娘 技術(shù)博客:http://www.reibang.com/u/05f416aefbe1
90后前端妹子嫂丙,愛編程,愛運營规哲,愛折騰跟啤。
堅持總結(jié)工作中遇到的技術(shù)問題,堅持記錄工作中所所思所見唉锌,對于博客上面有不會的問題隅肥,可以加入qq群聊來問我:473819131。