Vuejs – Converting a String to Object – Vuejs string to object Parsing JSON

Vuejs – Converting a String to Object – Vuejs string to object Parsing JSON

Vuejs object to json

We pass an simple object as the second data parameter to using this method. It has properties of template, props, data, and methods or function and Present a form to enter a simple haystack and keyword(s) to search

How to convert a json string to an object

index.html

[php]

Latest Vue.js products

vuejs/vue@{{ newcpost }}

[/php]

index.js

[php]
var newurl = ‘https://infinityknow.com/repos/vuejs/vue/products?per_page=3&sha=’
var demo = new Vue({

READ :  AngularJs Forms Submit Post Method Example

el: ‘#demo’,

data: {
datanms: [‘dsp’, ‘w3free’],
newcpost: ‘dsp’,
products: null
},

created: function () {
this.getsdata()
},

watch: {
newcpost: ‘getsdata’
},

filters: {
truncate: function (v) {
var myline = v.indexOf(‘\n’)
return myline > 0 ? v.slice(0, myline) : v
},
formatDate: function (v) {
return v.replace(/T|Z/g, ‘ ‘)
}
},

methods: {
getsdata: function () {
var client = new XMLHttpRequest()
var oldself = this
client.open(‘GET’, newurl + oldself.newcpost)
client.onload = function () {
oldself.products = JSON.parse(client.responseText)
console.log(oldself.products[0].html_url)
}
client.send()
}
}
})

[/php]

JSON.springify, JSON.parse, eval and maninulating the string

[php]
this.currentItem=JSON.stringify(strData);
this.currentItem=JSON.parse(strData);
this.currentItem=eval(strData);
[/php]

Example

Vue.js object to json

[php]
JSON.parse(JSON.stringify(vm.$data))
[/php]

[php]
var stringvalu= `{
“id”: “0”,
“program_id”: “Vuejs”,
“program_name”: “Vuejs II” ,
“program_description” : “Vuejs II WORK”,
}`
[/php]

READ :  Angular Nested ng repeat Example with Demo

Empty data string is converted to object

[php]
this.currentItem = JSON.parse(stringvalu);
[/php]

convert string to Dom in vuejs

[php]
Template

{{{getlibs}}}

script
——
Vue.component(… , {
template: … ,
data: function () {
return …
}
},
computed: {
getlibs:function(){
// return directly html
var str=”

Welcome -javascript

“;
return str;
}
},
methods:{…}
});

this.list.forEach(function (obj) {
obj.editMode = false;
});
[/php]

Leave a Reply

Your email address will not be published. Required fields are marked *