image.png

    1. <template>
    2. <view class='goods_detail'>
    3. <swiper indicator-dots>
    4. <swiper-item v-for="(item,index) in swipers" :key="index">
    5. <image :src='item.src'></image>
    6. </swiper-item>
    7. </swiper>
    8. <view class='box1'>
    9. <view class='price'>
    10. <text>¥{{info.sell_price}}</text>
    11. <text>¥{{info.market_price}}</text>
    12. <view class='goods_name'>{{info.title}}</view>
    13. </view>
    14. </view>
    15. <view class='line'></view>
    16. <view class='box2'>
    17. <view>货号:{{info.goods_no}}</view>
    18. <view>库存:{{info.stock_quantity}}</view>
    19. </view>
    20. <view class='line'></view>
    21. <view class='box3'>
    22. <view class='tit'>详情介绍</view>
    23. <view class='content'><rich-text :nodes="content"></rich-text></view>
    24. </view>
    25. </view>
    26. </template>
    27. <script>
    28. export default {
    29. data() {
    30. return {
    31. id: 0,
    32. swipers: [],
    33. info:{},
    34. content:null
    35. }
    36. },
    37. methods: {
    38. //获取轮播图的数据,首先会有函数
    39. async getSwipers() {
    40. const res = await this.$myRequest({
    41. url: '/api/getthumimages/' + this.id
    42. })
    43. this.swipers = res.data.message
    44. },
    45. async getDetailInfo(){
    46. const res = await this.$myRequest({
    47. url:'/api/goods/getinfo/'+this.id
    48. })
    49. this.info = res.data.message[0]
    50. },
    51. async getDetailContent(){
    52. const res= await this.$myRequest({
    53. url:'/api/goods/getdesc/'+this.id
    54. })
    55. this.content = res.data.message[0].content
    56. }
    57. },
    58. onLoad(options) {
    59. // console.log(options)
    60. this.id = options.id
    61. this.getSwipers()
    62. this.getDetailInfo()
    63. this.getDetailContent()
    64. }
    65. }
    66. </script>
    67. <style lang="scss">
    68. .goods_detail {
    69. swiper {
    70. height: 750rpx;
    71. image {
    72. width: 100%;
    73. height: 100%;
    74. }
    75. }
    76. .box1 {
    77. padding: 10px;
    78. .price {
    79. font-size: 35rpx;
    80. color: $shop-color;
    81. line-height: 80rpx;
    82. text:nth-child(2) {
    83. color: #ccc;
    84. font-size: 28rpx;
    85. text-decoration: line-through;
    86. margin-left: 20rpx;
    87. }
    88. }
    89. .goods_name {
    90. font-size: 35rpx;
    91. line-height: 60rpx;
    92. color:#333;
    93. }
    94. }
    95. .box2{
    96. padding:10rpx 20rpx;
    97. font-size: 35rpx;
    98. line-height: 60rpx;
    99. }
    100. .box3{
    101. .tit{
    102. font-size: 40rpx;
    103. padding-left: 10px;
    104. border-bottom: 1px solid #eee;
    105. line-height: 70rpx;
    106. }
    107. .content{
    108. padding:10px;
    109. font-size:28rpx;
    110. color:#333;
    111. line-height: 50rpx;
    112. }
    113. }
    114. }
    115. .line{
    116. height:10rpx;
    117. width:750rpx;
    118. background: #eee;
    119. }
    120. </style>

    接下来有几个注意点

    • 如果字符串中有标签需要解析,可以是用 rich-text :node=''> 方法。
    • 图片不能显示全并且加了样式也不起作用,可以将样式放入全局样式中 APP.VUE 文件中。