I need help with a very short vue script

I don’t know how familiar you guys are with vue, but here goes.
I am testing a very simple script.
When I click on an image I want a sound to play, and when I press “a” I want the same sound to play. very basic.
The first part works, but once I entered “created()” I got a parsing error “Unexpected token”.
I don’t understand what I did wrong here?

<div id="app">
  <img src="images/crash.png" alt="drum" v-on:click="play1">
  <audio ref="audioElm1" src="sounds/crash.mp3"></audio>
	<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
	<script src="main.js"></script>
new Vue({
  el: '#app',
  methods: {
    play1: function() {
  created() {
    document.addEventListener("keypress", (event) => {
		case 65: this.$refs.audioElm1(event.key)

Spaces are illegal in plain property names.

I think that you can enclose it in quotes if you really need a space there.

    document.addEventListener("keypress", (event) => {
		"case 65": this.$refs.audioElm1(event.key)

except that makes no sense either, Paul. The second half of the AddEventListener must be a function. They’re not defining an object there, that’s an arrow-function body.

Think the OP missed a switch statement.

You’re right. More information is needed.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.