detail.uvue 1.5 KB
Newer Older
W
微调  
wanganxp 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<template>
	<!-- #ifdef APP -->
	<scroll-view style="flex: 1">
	<!-- #endif -->
    <view class="banner">
      <image class="banner-img" :src="cover"></image>
      <text class="banner-title">{{title}}</text>
    </view>
    <rich-text :nodes="htmlNodes" style="padding: 3px"></rich-text>
	<!-- #ifdef APP -->
	</scroll-view>
	<!-- #endif -->
</template>

<script>
	export default {
		data() {
			return {
				htmlNodes: "",
				title: '',
				cover: "",
				post_id: "",
			}
		},
25
		onLoad(event: OnLoadOptions) {
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
26 27 28 29 30
      if (event != null) {
        this.post_id = event["post_id"] ?? "";
        this.cover = event["cover"] ?? "";
        this.title = event["title"] ?? "";
      }
W
微调  
wanganxp 已提交
31 32 33 34 35 36 37 38
			this.getDetail();
		},
		methods: {
			getDetail() {
				uni.request({
					url: 'https://unidemo.dcloud.net.cn/api/news/36kr/' + this.post_id,
					success: (data) => {
            if (data.statusCode == 200) {
39
              const result = data.data as UTSJSONObject
W
微调  
wanganxp 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
              // console.log(result["content"]);
              this.htmlNodes = result["content"] as string;
            }
					},
					fail: () => {
						console.log('fail');
					}
				});
			},
		}
	}
</script>

<style>
	.banner {
		height: 360rpx;
		overflow: hidden;
		position: relative;
		background-color: #ccc;
	}

	.banner-img {
		width: 100%;
	}

	.banner-title {
		max-height: 84rpx;
		overflow: hidden;
		position: absolute;
		left: 30rpx;
		bottom: 30rpx;
		width: 90%;
		font-size: 32rpx;
		font-weight: 400;
		line-height: 42rpx;
		color: white;
	}
77
</style>