PHP外部JSON进入Vuejs列表

时间:2016-08-14 20:27:38

标签: javascript php json vue.js

这给了我错误:Uncaught SyntaxError:JSON输入的意外结束

我正在尝试通过php检索外部JSON并提供一个Vue组件来列出"数据"之下的广告系列的名称。在JSON中。

我很难搞清楚这一点。提前感谢任何可以帮助我的人!

<?php
/**
 * The template for displaying the campaigns.
 *
 * Template name: Campaigns
 *
 */

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "http://brain.snappykraken.dev/templates",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_POSTFIELDS => "",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache"
  ),
));

$campaigns = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
}



?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
              <campaigns list="<?php echo json_encode($campaigns); ?>"></campaigns>
        </main><!-- #main -->
    </div><!-- #primary -->
<template id="campaigns-template">
    <h1>My Campaigns</h1>
    <ul class="list-group">
        <li class="list-group-item" v-for="campaigns in list">
            {{ campaign.name }}
        </li>
    </ul>
</template>
<script>
Vue.config.devtools = true
Vue.component('campaigns', {
    template: '#campaigns-template',
    props: ['list'],
    created() {
        this.list = JSON.parse(this.list);
    }
});
new Vue({
  el: 'body'
});
</script>

这是被引入的JSON:

{&#34;总&#34;:2&#34; per_page&#34;:15,&#34; CURRENT_PAGE&#34;:1,&#34; last_page&#34;:1,&# 34; next_page_url&#34;:空,&#34; prev_page_url&#34;:空,&#34;从&#34;:1,&#34;至&#34;:2&#34;数据&#34; :[{&#34; ID&#34;:1,&#34; fleet_id&#34;:1,&#34; audience_id&#34;:1,&#34;名称&#34;:&#34;投资极端&#34;,&#34;描述&#34;:&#34;这是对活动的描述是啊uhuhuhuh!&#34;,&#34; zapier&#34;:&#34;&#34; ,&#34; deleted_at&#34;:null,&#34; created_at&#34;:&#34; 2016-08-11 00:31:34&#34;,&#34; updated_at&#34;:&# 34; 2016-08-11 00:31:34&#34;},{&#34; id&#34;:2,&#34; fleet_id&#34;:1,&#34; audience_id&#34;:1 ,&#34;名称&#34;:&#34;投资平庸&#34;,&#34;描述&#34;:&#34;这是对其他&#34;,&#34; zapier&#的描述34;:&#34;&#34;,&#34; deleted_at&#34;:null,&#34; created_at&#34;:&#34; 2016-08-11 00:31:34&#34;, &#34; updated_at&#34;:&#34; 2016-08-11 00:31:34&#34;}]}

注意:我使用的是最新的vue.min.js和vue-resource.min.js

0 个答案:

没有答案