This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-h5/src/DoricElement.ts

30 lines
837 B
TypeScript
Raw Normal View History

2019-12-19 10:42:57 +08:00
import axios from 'axios'
2019-12-19 13:07:33 +08:00
import { DoricContext } from './DoricContext'
2019-12-19 10:42:57 +08:00
export class DoricElement extends HTMLElement {
source: string
alias: string
2019-12-19 13:07:33 +08:00
context?: DoricContext
2019-12-19 10:42:57 +08:00
constructor() {
super()
this.source = this.getAttribute('src') || ""
this.alias = this.getAttribute('alias') || this.source
axios.get<string>(this.source).then(result => {
this.load(result.data)
})
}
load(content: string) {
2019-12-19 13:07:33 +08:00
this.context = new DoricContext(content)
2019-12-19 20:44:14 +08:00
const divElement = document.createElement('div')
divElement.style.height = '100%'
this.append(divElement)
this.context.rootNode.view = divElement
2019-12-19 13:34:56 +08:00
this.context.init({
2019-12-19 20:44:14 +08:00
width: divElement.offsetWidth,
height: divElement.offsetHeight,
2019-12-19 13:34:56 +08:00
})
2019-12-19 10:42:57 +08:00
}
}