Giter VIP home page Giter VIP logo

Comments (4)

J2thearo avatar J2thearo commented on May 20, 2024 1

Thanks for the quick answer! In fact, iooxa exists when I inspect the html document in the console.

Screenshot 2020-08-05 20 19 39

But when I try to access iooxa in the linked index.js file, the variable is not recognized and I get a reference error.

Screenshot 2020-08-05 20 20 45

Here is my index.html setup

Screenshot 2020-08-05 20 20 17

I can't find any explanation for it.

from article.

rowanc1 avatar rowanc1 commented on May 20, 2024

To get iooxa running, are you using something like:

<script async src="https://unpkg.com/@iooxa/article"></script>

If so, there should be a global variable put onto the page (here), the interface that is provided for that variable is here. Try going to https://iooxa.dev, opening up the console - and there is an iooxa variable in the global namespace.

You should be able to create new variables using the createVariable function, and use getVariableByName or select the DOM and set existing variables.

The command

const v = iooxa.createVariable('scope.name', 3);

creates a new variable that does not have a DOM element, this is equivalent to:

<r-scope name="scope">
  <r-var name="name" value="3"></r-var>
</r-scope>

Using the javascript API is lower level, and likely doesn't need to be used if you are scripting with the components, probably the best way is to use the HTML and then if you need access to the variable, use the getVariableByName function or select it in the DOM.

Once you have the variable, you can update or get the value of it using:

// Select it in the dom
const r = document.getElementById('id').$runtime;
// OR use iooxa to get it by name
const r = iooxa.getVariableByName('scope.name');
// Then you can get access to the variable value (or change the value etc.):
r.get();

Hopefully that helps a bit, happy to clarify or further explain. It might be helpful to explain your use case and I can maybe give some further pointers.

from article.

J2thearo avatar J2thearo commented on May 20, 2024

Ok, I just noticed that the error is caused by the async inside the <script> tag. Without it, it works fine.

from article.

rowanc1 avatar rowanc1 commented on May 20, 2024

Almost got to commenting on the async before you. Glad you figured it out!

The other thing that might help is that you can put an arbitrary function in the callbacks of sliders, etc.

<script>
function hello(x, y) {
  console.log(`The values of x and y is: ${x}, ${y}`)
}
</script>
<r-var name="x" value="20"></r-var>
<r-var name="y" value="40"></r-var>
<r-button dense :click="hello(x, y)"></r-button>

from article.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.