<template>
<p id=
"newsDetails"
>
<mt-header title=
"详情"
>
<router-link to=
"/"
slot=
"left"
>
<mt-button icon=
"back"
></mt-button>
</router-link>
</mt-header>
<p
class
=
"details clearfloat"
>
<h1
class
=
"titleFont"
>
{{ title }}
</h1>
<p
class
=
"clearfloat sourceWrap"
>
<ul
class
=
"sourceFont"
>
<li v-
if
=
"(pubNews==true)"
>
<span
class
=
"source"
>{{pubName}}</span>
</li>
<li>
<span
class
=
"authorName"
>{{authorName}}</span>
<span
class
=
"time"
>{{createAt|formatTime}}</span>
</li>
</ul>
<span v-
if
=
"(pubNews==true)"
class
='btnFollow' @click=
"follow"
>关注</span>
</p>
<p
class
=
"bodyFont clearfloat"
id=
"bodyFont"
ref=
"bodyFont"
:
class
=
"{bodyHeight:contentStatus}"
>
<p v-html=
"content"
></p>
<p
class
=
"editor"
v-
if
=
"editorName"
>责任编辑:{{editorName}}</p>
</p>
<p
class
=
"contentToggle"
@click=
"contentStatus=!contentStatus"
v-
if
=
"contentStatus"
>阅读全文</p>
<Related :related=
"related"
></Related>
<!--重点是这里 父组件向子组件传值-->
</p> </p> </template>
import { Toast } from 'mint-ui';
import {mapState} from 'vuex'
import Related from './Related.vue'
import moment from 'moment';
export
default
{
name:
"NewsDetails"
,
components:{
Related,
},
data(){
return
{
id:this.
$route
.params.id,
topicType:
"news"
,
contentStatus:false,
curHeight:0,
bodyHeight:5000,
hotCommentScrollTop:0
}
},
created(){
this.id=this.
$route
.params.id;
this.fetchData();
moment.locale('zh-cn');
},
mounted(){
setTimeout(()=>{
this.contentToggle();
},500)
},
watch: {
'
$route
'(to,from){
this.id=this.
$route
.params.id;
this.fetchData();
}
},
computed: {
...mapState({
title: state => state.newsDetails.title,
authorName: state => state.newsDetails.authorName,
pubNews: state => state.newsDetails.pubNews,
pubName: state => state.newsDetails.pubName,
editorName: state => state.newsDetails.editorName,
createAt: state => state.newsDetails.createAt,
content: state => state.newsDetails.content,
myFavourite: state => state.newsDetails.myFavourite,
related: state => state.newsDetails.related,
})
},
filters:{
formatTime(time){
return
moment(time).fromNow();
},
},
methods:{
fetchData(){
this.
$store
.dispatch('getDetails',this.id);
},
follow(){
Toast('登录后进行关注');
this.
$router
.push(
"/login"
);
},
contentToggle(){
this.curHeight=this.
$refs
.bodyFont.offsetHeight;
if
(parseFloat(this.curHeight)>parseFloat(this.bodyHeight)){
this.contentStatus=true;
}
else
{
this.contentStatus=false;
}
console.log(this.hotCommentScrollTop);
},
}
}