javascript中localStorage的效率

时间:2019-04-17 19:48:50

标签: javascript local-storage

因此,我基本上想建立一个博客文章网站,您可以在其中主要使用页面发布文本,并在另一个页面上显示这些文章。我想使用本地存储将标题(或文章)和正文保存为对象。我的问题是,如果浏览器必须加载100个以上的对象(物品),那么效率如何?

一种替代方法是将文章另存为本地文件,然后从那里加载。

关于如何制作博客文章系统的其他想法?

  // const posts = [
  //   {title: "Post One", body: "This is post one"},
  //   {title: "Post Two", body: "This is post two"}
  // ];

  const posts = [
    // {title: "", body: ""}
  ];

  let name = "obj" + 7;

  var localObj = JSON.parse(localStorage.getItem(name));
  posts.push(localObj);

  var article = document.getElementById('post');

  function getPosts(){
    let output = "";
    posts.forEach((post, index) => {
      output += `<article><h1>${post.title}</h1><p>${post.body}</p></article>`
    });
    article.innerHTML = output;
  }

  getPosts();

  console.log(localStorage);

0 个答案:

没有答案