微信小程序如何訪問公眾號文章
前言
隨著小程序不斷的發(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>
為了達到效果,更加具體的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
//獲取應用實例
var app = getApp();
var cardTeams;
Page({
data: {
cardTeams: [{
"viewid": "1",
"imgsrc": "../../images/win/1.jpg",
"price": "¥1245",
"count": "一個40歲老碼農的總結,",
"name": "一個40歲老碼農的總結,奮斗",
}, {
"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": "女程序媛面試總結:我",
"name": "女程序媛面試總結:我是這",
},
{
"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>
注意:
小程序要和公眾號關聯(lián),鏈接才可以打開。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
JavaScript中Location.search處理使用方法
本文主要介紹了JavaScript中Location.search處理使用方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-04-04
uniapp 如何設置 tabbar 的 midButton 按鈕
在UniApp開發(fā)中,設置TabBar的midButton按鈕可以增加用戶交互的便利性,本文介紹了在App.vue中監(jiān)聽事件的方法,并提供了官方文檔鏈接作為參考,通過這種方式可以實現(xiàn)TabBar中的特殊按鈕功能,提升應用的用戶體驗2024-10-10
Bootstrap 設置datetimepicker在屏幕上面彈出設置方法
datetimepicker默認是在輸入框下面彈出的,但是遇到輸入框在屏幕下面時,日期選擇框會有一部分在屏幕下面,顯示不了,因此需要能夠從上面彈出,下面小編給大家介紹下Bootstrap 設置datetimepicker在屏幕上面彈出的設置方法2017-03-03
詳解JS中的compose函數(shù)和pipe函數(shù)用法
這篇文章主要介紹了JS中的compose函數(shù)和pipe函數(shù)用法,想深入了解Javascript的同學,可以參考下2021-04-04

