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
pengfei.zhou d0f1320656 move dir
2019-12-21 23:37:21 +08:00

30 lines
837 B
TypeScript

import axios from 'axios'
import { DoricContext } from './DoricContext'
export class DoricElement extends HTMLElement {
source: string
alias: string
context?: DoricContext
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) {
this.context = new DoricContext(content)
const divElement = document.createElement('div')
divElement.style.height = '100%'
this.append(divElement)
this.context.rootNode.view = divElement
this.context.init({
width: divElement.offsetWidth,
height: divElement.offsetHeight,
})
}
}