基于vue将json绘制图
Vue布局撰写者 (vue-layout-composer)
Dynamic, drag & drop, JSON-based grid layout for Vue.
Vue基于JSON的动态,拖放式网格布局。
Create your components, specify your JSON layout configuration and let the vue-layout-composer handle the rest.
创建您的组件,指定JSON布局配置,然后让vue-layout-composer处理其余部分。
安装 (Installation)
yarn add vue-layout-composer
yarn add vue-layout-composer
OR
要么
npm install vue-layout-composer --save
npm install vue-layout-composer --save
用法 (Usage)
Add the
VueLayoutComposer
plugin in yourmain.js
在您的
main.js
添加VueLayoutComposer
插件
Vue.use(VueLayoutComposer)
Use the
LayoutComposer
component使用
LayoutComposer
组件
<template>
<div id="app">
<layout-composer
:displayComponents="displayComponents"
:config="config"
@change:config="onConfigChange"
/>
</div>
</template>
<script>
import config from '../config/layout.json'
import 'vue-layout-composer/dist/vue-layout-composer.css'
import Item from './components/Item'
export default {
name: 'app',
data() {
return {
displayComponents: {
'Item': Item,
},
}
},
methods: {
onConfigChange(newConfig) {
console.log(newConfig)
},
},
}
</script>
示例布局配置(JSON) (Example layout config (JSON))
{
"component": "Layout",
"props": {
"orientation": "vertical"
},
"children": [
{
"component": "Layout",
"props": {
"orientation": "horizontal"
},
"children": [
{
"component": "Item",
"display": {
"weight": 1
},
"props": {
"background": "#E6E7E8",
"content": "This"
},
"hello": "world"
},
{
"component": "Item",
"display": {
"weight": 2
},
"props": {
"background": "#E6E7E8",
"content": "is"
},
"hello": "world"
},
{
"component": "Layout",
"props": {
"orientation": "ve