just want to set a value when the button is clicked and have it updated in the UI. what am i missing?
here’s the entire code:
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<div id="app">
<button @click="app.$set(app.item, 'uuid', getNewUUID())">
click me
</button>
<div>UUID: {{ item.uuid }}</div>
</div> <!-- end of div#app -->
<!-- JAVASCRIPT ONLY BELOW THIS POINT -->
<script type="text/javascript" src="../_js/axios.0.19.2.min.js"></script>
<script type="text/javascript" src="../_js/vue.2.6.11.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
item: {},
},
methods: {
async getNewUUID() { //<---- works flawlessly
let uuid = await axios.get('getNewUUID.php')
console.log({uuid}, uuid.data)
return uuid.data
}, // getNewUUID
},
})
</script>
</body>
</html>
as soon as i click the button i get this error:
TypeError: can't access property "$set", app is undefined
and these warnings:
[Vue warn]: Property or method "app" is not defined on the instance but referenced
during render
[Vue warn]: Error in v-on handler: "TypeError: can't access property "$set",
app is undefined"
sigh. how is app
not defined? i tried simply doing an assignment: itemuuid = getNewUUID()
, which generated an id and logged it to console, but didn’t update the UI. while i don’t know why, i DO know that in such cases, a $set
is used to trigger the reactivity. and it works when in a method, it just doesn’t work when placed on a UI element. i don’t want to have to create three methods to do the same thing for various implementations, i just want one function. i know. crazy, right?
EDIT: i know i flagged this, and that’s fine, but i would like to know why this is doing what it’s doing. i just don’t want to be a PITA…