Created
July 16, 2019 15:05
-
-
Save gbrennon/769526522554163b1c97377a34084eff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BaseForm = Vue.extend({ | |
template: ` | |
<form> | |
<block name="header"> | |
<h1>{{ title }}</h1> | |
</block> | |
<block name="content">Form inputs go here</block> | |
<block name="actions"> | |
<button @click="saveRecord">Save</button> | |
<button @click="deleteRecord">Delete</button> | |
</block> | |
</form> | |
`, | |
data () { | |
return { | |
title: 'Base Title', | |
apiUrl: null, | |
record: {} | |
} | |
}, | |
methods: { | |
saveRecord () { | |
// axios.post(this.apiUrl + this.record.id)... | |
}, | |
deleteRecord () { | |
// axios.delete(this.apiUrl + this.record.id)... | |
} | |
} | |
}) | |
const PersonForm = BaseForm.extend({ | |
template: ` | |
<extend> | |
<div block="header"> | |
{{ title }} From Person Form | |
<button @click="saveRecord">Save from header</button> | |
</div> | |
<div block="content"> | |
<input type="text" v-model="record.name" /> | |
<input type="text" v-model="record.age" /> | |
<button @click="incAge">Increase age</button> | |
</div> | |
</extend> | |
`, | |
data () { | |
return { | |
title: 'My Title', | |
apiUrl: '/api/my/', | |
record: { | |
id: 1, | |
name: '', | |
age: 0 | |
} | |
} | |
}, | |
methods: { | |
incAge () { | |
this.record.age++ | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment