简体   繁体   English

TypeError:无法读取未定义的“已创建”属性,未定义错误“Vue” Vue.js 3

[英]TypeError: Cannot read property 'created' of undefined, error 'Vue' is not defined Vue.js 3

i'm trying to use Custom Directives in vue.js 3 from the documentation, and i use the example that in the documentation but i've these errors:我正在尝试在文档中使用 vue.js 3 中的自定义指令,并且我使用了文档中的示例,但我有这些错误:

  • 'Vue' is not defined. 'Vue' 未定义。

and when i remove "vue" from the Directive code these errors show in the console:当我从指令代码中删除“vue”时,这些错误会显示在控制台中:

  • Uncaught (in promise) TypeError: Cannot read property 'created' of undefined未捕获(承诺中)类型错误:无法读取未定义的“已创建”属性
  • Uncaught (in promise) TypeError: Cannot read property 'parentNode' of null未捕获(承诺中)类型错误:无法读取 null 的属性“parentNode”

I think these error cuz i use vue version 3 but i'm using Custom Directives that in Vue vesion 3 from documentation我认为这些错误是因为我使用 vue 版本 3,但我使用的是文档中 Vue vesion 3 中的自定义指令

main js:主要js:

import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import "bootstrap";
import "bootstrap/dist/css/bootstrap.min.css";
import "./scss/main.scss";
import "normalize.css";

createApp(App).use(store).use(router).mount("#app");

//Directive

const app = vue.createApp({})
app.directive('highlight', {
    beforeMount(el, binding) {
        el.style.background = binding.value
    }
})

component:零件:

<p v-highlight="'yellow'" class="content">{{ limit(content,90, 'more...') }}</p>

Could you help me你可以帮帮我吗

There's no object or function called vue in Vue 3, to register a global directive just you the app instance already defined like:在 Vue 3 中没有名为vue的 object 或 function 来注册一个全局指令,只需要你已经定义的应用程序实例,如:

...
const app=createApp(App)
app.use(store).use(router).mount("#app");

app.directive('highlight', {
    beforeMount(el, binding) {
        el.style.background = binding.value
    }
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 vue.js:属性或方法“”未定义,渲染错误:“TypeError:无法读取未定义的属性” - vue.js : Property or method "" is not defined, Error in render: "TypeError: Cannot read property '' of undefined" 为什么这个错误会出现 Uncaught (in promise) TypeError: Cannot read property 'created' of undefined in vue.js - why is this error coming Uncaught (in promise) TypeError: Cannot read property 'created' of undefined in vue.js Vue.js 计算属性:[Vue 警告]:渲染错误:“TypeError:无法读取未定义的属性‘userId’” - Vue.js computed property : [Vue warn]: Error in render: "TypeError: Cannot read property 'userId' of undefined" “类型错误:无法读取未定义的属性‘服务’”Vue.js + Vuefire - "TypeError: Cannot read property 'servicios' of undefined" Vue.js + Vuefire TypeError:无法读取未定义的属性“标题”。 Vue.js - TypeError: Cannot read property 'title' of undefined. Vue.js Vue.js TypeError:消息无法读取未定义的属性“ singlePost” - Vue.js TypeError: Message Cannot read property 'singlePost' of undefined TypeError:无法读取未定义的Flatpickr&Vue.js属性“ add” - TypeError: Cannot read property 'add' of undefined" Flatpickr & Vue.js Vue.js - 类型错误:无法读取未定义的属性“标题” - Vue.js - TypeError: Cannot read property 'title' of undefined Vue.js 错误:TypeError:无法读取未定义的属性 - Vue.js error: TypeError: Cannot read properties of undefined 无法读取vue.js中“未定义”的属性 - Cannot read property of 'Undefined' in vue.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM