经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 移动开发 » 微信小程序 » 查看文章
微信小程序如何访问公众号文章
来源:jb51  时间:2019/7/8 12:38:02  对本文有异议

前言

随着小程序不断的发展,现在个人的小程序也开放了很多功能了,个人小程序直接打开公众号链接。在群里看到的一款小程序,点击可以直接阅读文章了,所以琢磨了一下,写了一些源码。

主要代码:

  1. <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

  1. <navigator url="/pages/search/search" hover-class="changestyle">
  2. <view class="view-search">
  3. <input class="input" placeholder-class="input-placeholder" placeholder="输入文章和链接" bindinput="bindSearchInput" />
  4. <image class="button" src="/images/search.png" bindtap="tapSearch" />
  5. </view>
  6. </navigator>
  7.  
  8. <view class="container">
  9. <view wx:for="{{cardTeams}}" wx:key="{{cardTeam.viewid}}" wx:for-item="cardTeam" class="item" bindtap="bindViewTap">
  10. <image class="img" src="{{cardTeam.imgsrc}}" mode="scaleToFill"></image>
  11. <view class="number-wrapper">
  12. <text class="name">{{cardTeam.name}}</text>
  13. <view class="count-wrapper">
  14. <text class="count">{{cardTeam.count}}</text>
  15. </view>
  16. </view>
  17. </view>
  18. </view>

weixin.wxss

  1. .container {
  2. padding-top: 0;
  3. }
  4.  
  5. .item {
  6. width: 100%;
  7. height: 220rpx;
  8. position: relative;
  9. display: flex;
  10. margin: 10rpx 10rpx;
  11. border-bottom: 1px solid rgb(197, 199, 199);
  12. }
  13.  
  14. .item:first-child {
  15. margin-top: 0;
  16. }
  17.  
  18. .item .remove {
  19. width: 60px;
  20. height: 100%;
  21. background-color: red;
  22. position: absolute;
  23. top: 0;
  24. right: -60px;
  25. display: flex;
  26. justify-content: center;
  27. align-items: center;
  28. }
  29.  
  30. .item .number-wrapper {
  31. height: 100%;
  32. padding-top: 40rpx;
  33. flex-direction: column;
  34. justify-content: space-between;
  35. }
  36.  
  37. .item .ok {
  38. width: 60px;
  39. height: 100%;
  40. padding-right: 20rpx;
  41. display: flex;
  42. justify-content: center;
  43. align-items: center;
  44. background-color: #98f5ff;
  45. }
  46.  
  47. .item .img {
  48. width: 150rpx;
  49. height: 150rpx;
  50. padding: 20rpx;
  51. }
  52.  
  53. .number-wrapper .name {
  54. margin: 10rpx 10rpx 10rpx 10rpx;
  55. font-size: 39rpx;
  56. overflow: hidden;
  57. }
  58.  
  59. .number-wrapper .count-wrapper {
  60. display: flex;
  61. align-items: center;
  62. margin-left: 10rpx;
  63. font-size: 25rpx;
  64. }
  65.  
  66. .number-wrapper .count-wrapper .decrease-btn {
  67. font-size: 30rpx;
  68. }
  69.  
  70. .number-wrapper .count-wrapper .increase-btn {
  71. font-size: 30rpx;
  72. }
  73.  
  74. .number-wrapper .count-wrapper .count {
  75. margin: 0 1rpx 0 1rpx;
  76. font-size: 30rpx;
  77. }
  78.  
  79. .number-wrapper .price-wrapper .people {
  80. margin-left: 250rpx;
  81. font-size: 30rpx;
  82. }
  83.  
  84. /* 搜索框样式 */
  85.  
  86. .view-search {
  87. display: flex;
  88. flex-direction: row;
  89. height: 70rpx;
  90. margin: 20rpx;
  91. padding: 5rpx;
  92. border: 1px #e4e2e2 solid;
  93. border-width: thin;
  94. align-items: center;
  95. }
  96.  
  97. .input {
  98. flex: 1;
  99. height: 60rpx;
  100. }
  101.  
  102. .input-placeholder {
  103. color: #999;
  104. }
  105.  
  106. .button {
  107. width: 60rpx;
  108. height: 60rpx;
  109. }

weixin.js

  1. //index.js
  2. //获取应用实例
  3. var app = getApp();
  4. var cardTeams;
  5.  
  6. Page({
  7. data: {
  8. cardTeams: [{
  9. "viewid": "1",
  10. "imgsrc": "../../images/win/1.jpg",
  11. "price": "¥1245",
  12. "count": "一个40岁老码农的总结,",
  13. "name": "一个40岁老码农的总结,奋斗",
  14.  
  15. }, {
  16. "viewid": "2",
  17. "imgsrc": "../../images/win/2.jpg",
  18. "price": "¥2345",
  19. "count": "小公司打杂三年,意外拿到",
  20. "name": "小公司打杂三年,意外拿到美",
  21.  
  22. }, {
  23. "viewid": "3",
  24. "imgsrc": "../../images/win/3.jpg",
  25. "price": "¥2345",
  26.  
  27. "count": "作为一个有追求的前端程序媛作",
  28. "name": "作为一个有追求的前端程序媛",
  29.  
  30. }, {
  31. "viewid": "4",
  32. "imgsrc": "../../images/win/4.jpg",
  33. "price": "¥2345",
  34. "count": "女程序媛面试总结:我",
  35. "name": "女程序媛面试总结:我是这",
  36.  
  37. },
  38. {
  39. "viewid": "5",
  40. "imgsrc": "../../images/win/5.jpg",
  41. "price": "¥2345",
  42. "count": "前端工作那些年,怎么避?",
  43. "name": "前端工作那些年,怎么避免",
  44.  
  45. }
  46. ]
  47. },
  48.  
  49. //事件处理函数
  50. bindViewTap: function() {
  51. wx.navigateTo({
  52. url: '../weixinlink/weixinlink'
  53.  
  54. })
  55. },
  56. onLoad: function() {
  57. console.log('onLoad:' + app.globalData.domain)
  58.  
  59. }
  60.  
  61. })

文章界面

weixinlink.wxml

  1. <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>

注意:

小程序要和公众号关联,链接才可以打开。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号