Vue.js
This document shows you haw you can create an FamilyTree JS 2 Vue.js project.
-
Create a new project with a name familytree:
npm init vue@latest
-
Go to the project root folder:
cd familytree
-
Install dependencies
npm install
-
Download the package, extract and edit the familytree2.js file to add the following row at the end of it:
export default FamilyTree2
- Add your extracted familytree.js file to \src\assets folder.
-
Create file FamilyTree.vue in /src/components folder with the following content:
<template> <div id="tree" ref="tree"></div> </template> <script> import FamilyTree2 from "../assets/familytree2"; export default { name: 'tree', data() { return { nodes: [ {id: 1, spouseIds: [2], motherId: 3, fatherId: 4}, {id: 2}, {id: 3}, {id: 4}, ] } }, methods: { mytree: function(domEl, x) { this.familyTree = new FamilyTree2(domEl); this.familyTree.readOnly = false; this.familyTree.addFamilyMembers(x).draw(1); } }, mounted(){ this.mytree(this.$refs.tree, this.nodes) } } </script> <style scoped> </style>
-
Change App.vue as follows:
<template> <div id="familytree"> <FamilyTree /> </div> </template> <script> import FamilyTree from './components/FamilyTree.vue' export default { name: 'app', components: { FamilyTree, } } </script> <style> #app { font-family: 'Avenir', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } html, body { width: 100%; height: 100%; padding: 0; margin: 0; overflow: hidden; font-family: Helvetica; } #tree { width: 100%; height: 100%; } </style>
-
In main.css add this:
#app, #tree { height: 100%; width: 100%; display: block; }
-
Start the project:
npm run dev