Unable to access method from vanilla JavaScript in Vue 3 Custom Element

I've been working with a custom element called <ts-app> that I created using vue 3.

The emitted event is functioning correctly, but I'm having trouble figuring out how to call a method from vanilla JavaScript.

       customElements.whenDefined("ts-app").then((app) => {
            const el = document.querySelector("ts-app");

            // I want to call open inside webcomponent here 
            // tried el.open(), el.shadowRoot.open() both returns open is not defined
            

            el.addEventListener("updated", function (e) {
                //this is working fine
                console.log(e);
            });
        });

Within the component, my code looks like this:

methods: {
        open() {
            console.log('Open Called')
        },
}

Answer №1

To initialize a prop, you can define it like this:

const properties = defineProperties({
  isActivated: {
    type: Boolean,
    default: true,
  },
})

Next, observe changes to that prop using:

watch(
  () => properties.isActivated,
  (newValue) => {
    // execute action for activation ;
  }
);

Finally, in pure JavaScript, modify the prop value like so:

el.setAttribute('is-activated', false)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transform the Jquery code for filtering a list based on checkboxes to Vanilla JavaScript

Looking to convert a code snippet that filters a list based on data attributes from jQuery to JavaScript. $('.checkbox').change(function() { $('li.list').each(function(i, item) { var color = $(this).data('color'); ...

Eliminate any blank brackets in a JSON structure

Looking to extract certain elements from a JSON string. Input : "sample": [{},{},{},{},{},{},{}], Output : "sample": [], Attempted solution : var jsonConfig = JSON.stringify(jsonObj); var result = jsonConfig.replace(/[{},]/g, ''); // Global ...

Updating the scope variable in an AngularJS directive

Recently delving into Angular, I encountered an issue: I have both a list view and a details view with tags. To facilitate navigating between the two views and loading new elements from a service upon click events, I created a directive. My aim is to also ...

What is the best way to obtain the SearchIDs for various searchNames using JavaScript?

Who can assist me in resolving this issue? I am trying to retrieve the id of a searchName whenever a user selects the checkbox. Ideally, I would like to assign the value of the PHP line $search_row->searchid to the id attribute in the input field. Apolo ...

Creating an Angular table row that can expand and collapse using ng-bootstrap components is a convenient and

I need assistance with an application I am developing, where I want to expand a table row to display details when it is clicked. The issue I am facing is that currently, all rows expand and show the data of the clicked row as seen in the image result below ...

How do I go about showing every character on a separate line using a for loop?

var input = prompt("What is Lance attempting to convey?"); //user enters any text for (var i = 0; i <= input.length; i++) { var output = input.charAt(i); if (output == "e" || output == "o" || output == "a" || output == "u") { outp ...

What is the best way to add files to a different object in ReactJS?

I have a collection of files that need to be compressed before appending them to a new array. I'm struggling with adding files to the new array in a loop. Here's what I've tried: const [compressedFiles, setCompressedFiles] = useState([]); ...

How to retrieve a DOM element using Aurelia framework

When it comes to accessing a DOM element in Aurelia, what are the best practices to follow for different use cases? Currently, I have two scenarios in my Aurelia project: Firstly, within the template, there is a form that I need to access from the view-mo ...

What exactly is the purpose of measuring "First Load JS" in the @next/bundle-analyzer tool?

The analysis generated by the NextJS bundle analyzer appears as follows: Page Size First Load JS ┌ λ / 12 ...

Restricting the input field in jQuery to only accept the maximum value based on the

There are two input fields: discountType and discountAmount. My goal is to set restrictions based on the value of discountType: if it's percentage, the discountAmount input should only accept numbers between 0 and 100; if it's absolute, any numbe ...

Troubleshooting with Vuetify: Exploring methods to adjust the width of individual components within a banner

Seeking to incorporate a search form into a banner, utilizing vuetify. <v-banner app v-model="show" two-line transition="slide-y-transition"> <v-form> <v-text-field label="textfield" /> <v-select :items="select_1" label="sel ...

Oops! Vue.js encountered an issue where it couldn't access the property 'version' because it was undefined

Whenever I execute npm start, I encounter the following error message: ERROR TypeError: Cannot read property 'version' of undefined TypeError: Cannot read property 'version' of undefined It occurs after I have executed: npm install ...

Revamping the Meteor project with the latest Bootstrap-4 update

Currently, I am working on a Meteor project that utilizes Bootstrap v3. I am looking to upgrade this project to Bootstrap v4. What specific steps do I need to take in order to accomplish this transition? ...

PHP: Clarifying Column Names when Joining with Mysqli

In the scenario where data is lost due to conflicting column names in a JOIN operation, particularly when using PHP's mysqli and returning the result as a JSON object, there arises an issue. Let's consider a situation where two tables are relate ...

Exploring Nashorn's capabilities in parsing TypeScript

Recently, I came across a discussion suggesting that Nashorn in JDK 9 should have the capability to parse TypeScript. Excited to try it out, I attempted to use it like this: Parser parser = Parser.create(); CompilationUnitTree ...

Node.JS, R, and Python are used for intensive computing tasks such as identifying when a callback function has finished executing and

My Node.js REST API exposes endpoints that trigger R and Python scripts for complex computations. Prior to executing these scripts, I must first identify the callback, assign a unique ID to it, and quickly send back the ID to the consumer. The consumer wil ...

A method for performing precise division on numbers in JavaScript, allowing for a specific precision level (such as 28 decimal places)

I've searched extensively for a library that can handle division operations with more than 19 decimal places, but to no avail. Despite trying popular libraries like exact-math, decimal.js, and bignumber.js, I have not found a solution. How would you ...

How to perfect the alignment of TimePicker in angular UI

I'm dealing with the code below: <ul class="dropdown-menu custom-scroll dropdown-label custom-width" role="menu" aria-labelledby="btn-append-to-body" ng-show="!display" > <li role ...

Creating a schema that is compatible with both mongoose and graphql can be achieved by carefully designing the data structure to

What is the best way to structure a schema for use with React and Graphql utilizing promises? const Dog = mongoose.model('Dog', { breed: String }); ...

Include the providers after declaring the AppModule

When it comes to Angular 2+, providers are typically registered in the following manner: // Using the @NgModule decorator and its metadata @NgModule({ declarations: [...], imports: [...], providers: [<PROVIDERS GO HERE>], bootstrap: [...] }) ...