js deep nested object generator
js deep nested object generator
const obj = {
k1: {
id: 1,
k2: {
id: 2,
k3: {
id: 3,
k4: {
id: 4,
k5: {
id: 5,
k6: {
id: 6,
k7: {
id: 7,
k8: {
id: 8,
k9: {
id: 9,
k10: {
id: 10,
deep: 10,
}
}
}
}
}
}
}
}
}
}
};
const deep_nested_object_generator = (args = {}) => {
//
};
obj1 = _.cloneDeep(obj);
// {k1: {…}}k1: {id: 1, k2: {…}}__proto__: Object
obj.k1.id;
// 1
obj.k1.id = 11;
// 11
obj1.k1.id;
// 1
vue demo
<template>
<div id="app">
<div id="nav">
<router-link to="/">Home</router-link>
<br />
<router-link to="/about">About</router-link>
</div>
<router-view/>
</div>
</template>
<script>
import _ from 'lodash';
export default {
// name: 'app',
watch: {
$route (to, from) {
console.log('to', to);
console.log('from', from);
if (from.path.includes('/')) {
this.$oldRoute = _.cloneDeep(from);
// this.$oldRoute = JSON.parse(JSON.stringify(from));
// this.$oldRoute = from;
console.log('from', from);
console.log('this.$oldRoute', this.$oldRoute);
// params: {}
// path: "/about"
// query: {}
}
},
},
data () {
return {
$oldRoute: {},
ua: navigator.userAgent,
};
},
// ...
};
</script>
<style lang="scss">
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
#nav {
padding: 30px;
a {
font-weight: bold;
color: #2c3e50;
&.router-link-exact-active {
color: #42b983;
}
}
}
</style>
refs
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14656106.html
未经授权禁止转载,违者必究!