[英]How can I use a file.js in a component vue
I tried to use prueba.js in one of the components of my app (InputSwap.vue), in which there is a button ('console.log').我尝试在我的应用程序 (InputSwap.vue) 的其中一个组件中使用 prueba.js,其中有一个按钮 ('console.log')。 I want to use this file using that button, but the app showed me this error:
我想通过那个按钮来使用这个文件,但应用程序向我显示了这个错误:
enter image description here在此处输入图片说明
prueba.js let me see the data in the console by clicking the button. prueba.js 让我通过单击按钮在控制台中查看数据。 The data was saved with window.localStorage:
数据是用 window.localStorage 保存的:
window.localStorage.setItem('data_input', JSON.stringify(data));
where am I wrong?我错在哪里?
prueba.js : prueba.js :
export default {
infoPrueba() {
var data = (JSON.parse(window.localStorage.getItem('data_input')))
console.log(data)
}
}
InputSwap.vue: InputSwap.vue:
<template>
<div class="card-action">
<Button v-on:click="prueba()"
v-bind:style="{'margin-left' : '5px', background : '#52368c'}"
btext="Console.log" icon="code"
/>
</div>
</template>
<script>
import Button from './Button'
import * as prueba from './prueba.js' // I have prueba.js in components folder
export default {
name: 'InputSwap',
components: {Button},
methods: {
prueba: async function () {
prueba.infoPrueba()
},
},
}
</script>
Thanks to x-rw, I solved this problem:感谢 x-rw,我解决了这个问题:
I changed import * as prueba from './prueba.js' to import {infoPueba} from './prueba.js'我将 import * as prueba from './prueba.js' 改为 import {infoPueba} from './prueba.js'
and I wrote this code in prueba.js:我在 prueba.js 中写了这段代码:
export const infoPrueba = () => {
var data = (JSON.parse(window.localStorage.getItem('data_input')))
console.log(data)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.