我在 Aurelia 中创建了一个简单的自定义元素,它使用了一个@inlineView()
(因为视图很小)但是当我尝试从我的内联视图访问我的 VM 属性之一时,我只是得到“属性未定义”;
import {inlineView} from 'aurelia-framework';
@inlineView(`<template><h1>${title}</h1></template>`)
export class MyCustomElement {
constructor () {
this.title = 'Hello, World!';
}
}
Run Code Online (Sandbox Code Playgroud)
这@bindable
也会发生;
export class MyCustomElement {
@bindable title = 'Hello, World!';
constructor () {
}
}
Run Code Online (Sandbox Code Playgroud)
当<template><h1>${title}</h1></template>
被解释时,解释器会尝试插入title
尚不存在的变量。尝试这个:
@inlineView(`<template><h1 innerHTML.bind="title"></h1></template>`)
Run Code Online (Sandbox Code Playgroud)
或者更简单:
@inlineView('<template><h1>${title}</h1></template>') // without accents
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
96 次 |
最近记录: |