溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

vue.js如何實(shí)現(xiàn)數(shù)據(jù)庫的JSON數(shù)據(jù)輸出渲染到html頁面功能

發(fā)布時(shí)間:2021-04-19 13:56:40 來源:億速云 閱讀:1053 作者:小新 欄目:web開發(fā)

這篇文章主要介紹vue.js如何實(shí)現(xiàn)數(shù)據(jù)庫的JSON數(shù)據(jù)輸出渲染到html頁面功能,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

具體如下:

1、首先通過json.php把數(shù)據(jù)庫給輸出為json格式的數(shù)據(jù)

[
  {
    "id":1,
    "resname":"百度",
    "resimg":"http://www.baidu.com/1.jpg",
    "resint":"2018-1-18",
    "resurl":"http://www.baidu.com/1.apk",
    "pageview":"100"
  },
  {
    "id":2,
    "resname":"阿里巴巴",
    "resimg":"http://www.alibaba.com/1.jpg",
    "resint":"2018-1-18",
    "resurl":"http://www.alibaba.com/1.apk",
    "pageview":"200"
  },
  {
    "id":3,
    "resname":"騰訊",
    "resimg":"http://www.qq.com/1.jpg",
    "resint":"2018-1-18",
    "resurl":"http://www.qq.com/1.apk",
    "pageview":"300"
  }
]

然后通過vue.js來解析

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <title>VUE解析JSON數(shù)據(jù)</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
  <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
  <div id="main">
    <table border=1>
      <tr>
        <td>ID</td>
        <td>資源名稱</td>
        <td>LOGO</td>
        <td>更新時(shí)間</td>
        <td>下載地址</td>
        <td>閱讀量</td>
      </tr>
      <tr v-for="r in rows">
        <td>{{r.id}}</td>
        <td>{{r.resname}}</td>
        <td><img v-bind:src="r.resimg"/></td>
        <td>{{r.resint}}</td>
        <td><a v-bind:href="r.resurl" rel="external nofollow" >點(diǎn)擊下載</a></td>
        <td>{{r.pageview}}</td>
      </tr>
    </table>
  </div>
</body>
<script>
  $(document).ready(function () {
    $.getJSON("data.json", function (result, status) {
      var v = new Vue({
        el: '#main',
        data: {
          rows: result
        }
      })
    });
  });
</script>
</html>

最終運(yùn)行index.html

vue.js如何實(shí)現(xiàn)數(shù)據(jù)庫的JSON數(shù)據(jù)輸出渲染到html頁面功能

以上是“vue.js如何實(shí)現(xiàn)數(shù)據(jù)庫的JSON數(shù)據(jù)輸出渲染到html頁面功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI