ITPub博客

首页 > 应用开发 > > 请问vue从后台拿到对象数据后,怎么渲染在相应标签里?

请问vue从后台拿到对象数据后,怎么渲染在相应标签里?

作者:daxuesheng 时间:2019-08-12 15:25:03 0 删除 编辑

这是我的template里的内容:

<template>
  <div>
    <h1>news_detail</h1>
    <!--页面主体-->
    <div class="main container">
      <div class="news_details"  >
            <h2>这里需要放 title</h2>
            <span>发布时间: pubTime</span>
            <div class="news_content">
              这里是 content
          </div>
      </div>
    </div>
  </div>
</template>

以下是我在后台拿数据:

methods:{
        NewsCoutent:function(){
          this.$http.get('http://localhost/mfresh/data/news_detail.php?nid='+this.nid)
            .then((response)=>{
            this.newsContentList = response.data;
            console.log(response.data);
            console.log(this.newsContentList.title);
          })
        }
    },

第一个console.log在控制台的输出拿到的是对象:

{__ob__:Observer}

content:"

家居装饰也要“壕”一次,尤其是雾霾天气下家庭必备的空气净化器。近日净美仕在行业率先推出“千金”M8088A彩色版,可谓为空气净化器产业树立了个性化品牌的标杆。

..."

nid:(...)

pubTime:"1575856000000"

title:"1智能空气净化器翻盘:净美仕能否领衔?"

第二个console.log取title,也没问题:

1智能空气净化器翻盘:净美仕能否领衔?

在template里渲染的时候我用的v-for只能取到所有,不能取出单个值:

v-for="n of newsContentList"> //用in 也试了,也不行。

//第一个取出了所有数据

console.log({{n}});

//第二个拿不到数据,不能用 . 取吗?

console.log({{n.title}});

这个怎么渲染啊??


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4692/viewspace-3119246/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-05-22

  • 博文量
    176
  • 访问量
    24988