我正在学习 Aurelia 的工作原理,并且正在尝试让一个简单的自定义属性正常工作。它所要做的就是根据某些值的变化来改变 div 文本的颜色。
我有一个 div 有:
high.bind="changeColor"
在我的属性中,我有:
import {inject, customAttribute} from 'aurelia-framework';
@customAttribute('high')
@inject(Element)
export class High {
constructor(element) {
this.element = element;
}
valueChanged(newValue){
console.log(newValue);
if (newValue) {
this.element.classList.remove('highlight-yellow');
} else {
this.element.classList.add('highlight-blue');
}
}
在我的视图模型中,我有:
import {high} from './highlightattribute'
export class Welcome{
heading = 'Welcome to the Aurelia Navigation App!';
firstName = 'John';
lastName = 'Doe';
get fullName(){
return `${this.firstName} ${this.lastName}`;
}
get changeColor(){
if (this.firstName == 'John'){
return false;
}
return true;
}
welcome(){
alert(`Welcome, ${this.fullName}!`);
}
}
当我更改名字时,我没有看到在高自定义属性类中触发了 valueChanged 事件。