相关疑难解决方法(0)

在Vue3中使用过滤器但无法读取globalProperties

只是一个简单的问题,

我知道 Vue3 不再使用过滤器,并且注释说使用计算或方法代替。但还有一个我们可以使用的 globalProperties,我使用了这个 globalProperties 但不断收到此错误

未捕获的类型错误:无法读取未定义的属性“globalProperties”

有谁知道我的代码中的错误在哪里?

const app = {
data() {
    return {
        message: ""
    }
  }
}

app.config.globalProperties.$filters = {
formatDate(value) {

    if (value == "0001-01-01T00:00:00")
        return "";
    var today = new Date(value);
    var dd = String(today.getDate()).padStart(2, '0');
    var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
    var yyyy = today.getFullYear();

    today = dd + '/' + mm + '/' + yyyy;
    return today;
   }
}

Vue.createApp(app).mount('#app');
Run Code Online (Sandbox Code Playgroud)

我在表中使用过滤器,如下所示

    <td>
         {{ $filters.formatDate(incident.incidentData) }}
    </td>
Run Code Online (Sandbox Code Playgroud)

vue.js vuejs3

4
推荐指数
1
解决办法
4767
查看次数

标签 统计

vue.js ×1

vuejs3 ×1