0

Here I am filling the localStorage:

let storageObj = {};
storageObj.date = (new Date().toLocaleString().replace(", ","T"));
storageObj.url = this.responseURL;
localStorage.setItem(storageObj.date, storageObj.url);

In mounted() I am iterate all data from localStorage like:

for(let obj of Object.entries(localStorage))
{
    this.lastpasts.push(obj);
}

And placing every Object to lastpasts (located in data() {lastpasts : []}).

In template I want to print only url:

<div class="ui divided items" v-for="el in lastpasts">
    <div class="item">
    {{el.url}}
     </div>
</div>

But this code do not print nothing. Work only {{el}}. It's print in HTML block:

[ "24.06.2017T11:55:10", "362e9cc5-e7e6" ]
[ "24.06.2017T12:26:47", "b0f9f20d-7851" ]

Browser console do not have any errors.

7
  • Can you please put the result of console.log(el) ? Commented Jun 24, 2017 at 11:00
  • ReferenceError: el is not defined at <anonymous>:1:13 Commented Jun 24, 2017 at 11:04
  • Oh, sorry. My mistake. console.log(lastpasts) (or lastposts?) Commented Jun 24, 2017 at 11:04
  • lastpasts because it's code-past blocks. console.log(lastpasts) ReferenceError: lastpasts is not defined at <anonymous>:1:13 Commented Jun 24, 2017 at 11:07
  • Here is full code past.code123.org/61c68aeb-f4af Commented Jun 24, 2017 at 11:08

1 Answer 1

3

In the chat session we managed to solve his issue.

It was caused by the fact, that he was using Array of Arrays instead of Array of Objects. Because Array can be used only with index, not field name, {{el.url}} was not working.

The code to get values from LocalStorage had to be changed to:

mounted() { 
  for(let obj of Object.entries(localStorage)) { 
    var x = {}; 
    x.url = obj[0]; 
    x.date = obj[1]; 
    this.lastpasts.push(x);    
  } 
}

Now, it is possible to use {{el.url}}

Sign up to request clarification or add additional context in comments.

2 Comments

Oops i'll remove my answer cuz its the same and +1 for you
cheers. We were chatting and solving it together when you wrote your answer :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.