use register() method in app object to correctly register component scope
This commit is contained in:
parent
a377688175
commit
bf2c1bfa91
3 changed files with 11 additions and 6 deletions
|
@ -48,6 +48,7 @@ const appdata = {
|
|||
conf: {} as Config,
|
||||
components: {},
|
||||
output: '', // debug output space
|
||||
register,
|
||||
handle,
|
||||
poll,
|
||||
Data
|
||||
|
@ -55,6 +56,10 @@ const appdata = {
|
|||
|
||||
// App (appdata) methods
|
||||
|
||||
function register(name: string, comp: any) {
|
||||
this.components[name] = comp
|
||||
}
|
||||
|
||||
function handle(msg) {
|
||||
const [ domain, action, class_, item ] = msg.path.split('/')
|
||||
const comp = this.components[class_ || 'data']
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// comp-data.ts - definition and methods of the Data component
|
||||
|
||||
import { reactive } from 'petite-vue'
|
||||
import { sendMsg } from './common'
|
||||
|
||||
// Data component
|
||||
|
@ -24,7 +23,7 @@ export function Data(name: string, conf: any): object {
|
|||
chmode,
|
||||
copynew
|
||||
}
|
||||
this.components[name] = reactive(comp)
|
||||
//this.components[name] = comp
|
||||
if (comp.state.id) {
|
||||
sendMsg(this.conf, [domain, 'query', name, comp.state.id], {})
|
||||
}
|
||||
|
@ -34,11 +33,11 @@ export function Data(name: string, conf: any): object {
|
|||
// Data methods
|
||||
|
||||
function handle(parent: any, domain, action, class_, item, payload: string) {
|
||||
if (action == 'data') { // && this.state.id
|
||||
const data = JSON.parse(payload)
|
||||
const data = JSON.parse(payload)
|
||||
if (action == 'data') { // && this.state.id == item) {
|
||||
Object.assign(this.data, data)
|
||||
this.state.mode = 'view'
|
||||
} else if (action == 'response') {
|
||||
} else if (action == 'response') { // && data.rc == 3) {
|
||||
this.state.id = item
|
||||
window.location.hash = item
|
||||
sendMsg(parent.conf, [this.domain, 'query', this.name, item], {})
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
{{- $comp := .Get "component" | default "Data" -}}
|
||||
{{- $conf := merge $.Params (dict "domain" $domain "action" $action)
|
||||
| jsonify -}}
|
||||
<div v-scope="{{ $comp }}('{{ $name }}', {{ $conf }})">
|
||||
<div v-scope="{{ $comp }}('{{ $name }}', {{ $conf }})"
|
||||
@vue:mounted="register('{{ $name }}', valueOf())">
|
||||
{{ .Inner }}
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue