Cannot read properties of undefined (reading 'setOptions') error in vue markdown-editor - vue.js

I use vue markdown-editor component and I'm getting this error
vue.runtime.esm.js:1897 TypeError: Cannot read properties of undefined (reading 'setOptions')
at o.initialize (markdown-editor.vue:70:1)
at o.mounted (markdown-editor.vue:43:1)
at rt (vue.runtime.esm.js:1863:57)
at Rn (vue.runtime.esm.js:4235:7)
at Object.insert (vue.runtime.esm.js:3158:7)
at Y (vue.runtime.esm.js:6390:28)
at o.__patch__ (vue.runtime.esm.js:6609:5)
at o.On.e._update (vue.runtime.esm.js:3963:19)
at o.r (vue.runtime.esm.js:4081:10)
at rr.get (vue.runtime.esm.js:4495:25)
my code looks like this
<markdown-editor class="med" :configs="configs" v-model="messagetemplate.message"></markdown-editor>
I don't know how to add setOptions parameter. Thank you for the help!
edit: in markdown-editor.vue file I found this line marked.setOptions({ sanitize: this.sanitize });

Related

Laravel $data is undefined error but i defineted it on fuctions

I have a data $data["dil1"]="Yasin"; and i added this data to title with #section('title'){{$dil1}} - Yönetim Paneli #endsection but i get this error message when i try to run codes: $dil1 is undefined
How can i fix it ? or what's the main problem ?
Thank you

Cant load content – TypeError: Cannot read properties of null (reading 'attributes‘)

currently working on an issue and cant figure out why my page throws me an error.
Having this component:
<JobDetailSectionText
:variant="tmpl({ red: 1, blue: 4, yellow: 7 })"
:image-src="
jobProfile.attributes.imagePractice
? $strapi.options.url +
jobProfile.attributes.imagePractice.data.attributes.url
: '/static/img/praxisteil.jpg'
"
:image-alt="
jobProfile.attributes.imagePractice.data.attributes.alternativeText
"
>
In my content manager in Strapi I changed the „attribute.imagePractice" from required = true to false and now want to, if no file is added to the database show a default image in '/static/img/praxis.jpg‘.
But the console of the page gives me an error
"TypeError: Cannot read properties of null (reading 'attributes')
I tried to figure out the source of the problem but the page only works if I add and imagePractice in the backend, it won’t take the default img I tried to declare with the static path.
Any thoughts?
Thanks!
You can use optional chaining to check if property is exist
<JobDetailSectionText
...
jobProfile.attributes?.imagePractice
? $strapi.options.url +
jobProfile.attributes.imagePractice.data.attributes.url
: '/static/img/praxisteil.jpg'
"
...
>
#DinhTX solution is good, but note, that you cannot use optional chaining unless it's Vue 3. Read more here.
If you're using Vue version less then 3 you would need to write a computed property for that src attribute value where you'd check if attributes exist. Actually, I'd recommend you to use computed property anyway cause Vue's templates should be more HTML and less JS (not like React).
Example of computed property would be:
computed: {
jobSrc() {
const strapiUrl = `${$strapi.options.url}${jobProfile.attributes.imagePractice.data.attributes.url}`
return jobProfile.attributes?.imagePractice ? strapiUrl :'/static/img/praxisteil.jpg'
}
}

[Vue warn]: Error in v-on handler: "TypeError: Cannot read property 'length' of undefined"

I am facing this error. Can I know if there is anything wrong with my code?
validateEmail(){
const emailregex = /^[a-zA-Z0-9+_.-]+#[a-zA-Z0-9.-]+$/
const emailmatch = emailregex.test(this.userObj.user.email)
if((!emailmatch) || (this.userObj.user.email.length == undefined)){
this.errors = []
console.log(this.userObj.user.email)
this.errors.push("Email is not valid")
}
I am trying to validate an email address using regex
If you're not sure that your regex is valid, you can check it against some test strings here: https://rubular.com/
This way, you'll eliminate a possible regex bug.
Probably this.userObj.user.email is undefined, try with optional chaining (?.) like this:
this.userObj.user.email?.length == undefined

ERROR TypeError: Cannot read property 'project_name' of undefined - Angular 8

My ts code coding is,
this.api.getPay(this.donationId).subscribe(
data => {
this.paymentData = data;
this.paymentDetails = this.paymentData.donationDetails[0];
}
)
My html code is like
Project : <strong>{{paymentDetails.project_name}}</strong><br/>
Status: <strong>{{paymentDetails?.status}}</strong><br/>
Now project_name and Status details will be displayed. Console gets "ERROR TypeError: Cannot read property 'project_name' of undefined"
If I added "?" like
{{paymentDetails?.project_name}}
No Details displayed. But console not having any Error.
This same coding method works well in Angular 5/6.
Any special method for Angular 8 ???
MY console output in TS file is
{
project_name: "test",
status: "true"
}
Previous question is How to Display Values in Angular 8 Shows ERROR TypeError: Cannot read property 'project_name' of undefined
but solution not working
anyone know how to resolve ?
Everything seems good, check if your component doesn't have
changeDetection: ChangeDetectiongStrategy.OnPush
If so, remove it and put back the '?' in the html markup, and then add it back and do the change detection in the subscribe

Cannot read property 'backgroundColor' of undefined

When the function call below gets run it returns this error.
"Uncaught TypeError: Cannot read property 'backgroundColor' of
undefined" I am trying to change the background color of a class called
.jumbotron. I have tried everything I can thing of so far.
Could anyone tell me why this is happening?
clrElementJumbo("cornsilk");
function clrElementJumbo(scolor) {
var el = document.getElementsByClassName("jumbotron");
el.style.backgroundColor = scolor;
}
Try to replace the code
var el = document.getElementsByClassName("jumbotron");
with the following
var el=document.getElementsByClassName("jumbotron")[0];