首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >将javascript添加到vue组件<script>标记时出现"ReferenceError:$ is not defined“

将javascript添加到vue组件<script>标记时出现"ReferenceError:$ is not defined“
EN

Stack Overflow用户
提问于 2018-09-18 08:11:33
回答 2查看 320关注 0票数 -1

在尝试添加代码以自动展开文本框时,我得到了这个错误--来自以下代码:https://codepen.io/vsync/pen/frudD。我需要以不同的方式添加它吗?它当前位于vue组件文件中的脚本标记之间。

代码语言:javascript
复制
Uncaught ReferenceError: $ is not defined
    at eval (Pastes.vue?58dd:23)
    at Object../node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/pages/pastes/Pastes.vue (app.js:782)
    at __webpack_require__ (app.js:679)
    at fn (app.js:89)
    at eval (Pastes.vue?fa7c:1)
    at Object../src/components/pages/pastes/Pastes.vue (app.js:1220)
    at __webpack_require__ (app.js:679)
    at fn (app.js:89)
    at eval (index.js?3672:1)
    at Object../src/router/index.js (app.js:1252)
EN

回答 2

Stack Overflow用户

发布于 2018-09-18 08:22:40

确保您加载的是jquery库,您可以遵循此guide或此one

票数 1
EN

Stack Overflow用户

发布于 2018-09-18 09:31:23

我使用了下面的代码,它工作得很好。

https://jsfiddle.net/cferdinandi/mqwwpL6u/

代码语言:javascript
复制
var autoExpand = function (field) {

    // Reset field height
    field.style.height = 'inherit';

    // Get the computed styles for the element
    var computed = window.getComputedStyle(field);

    // Calculate the height
    var height = parseInt(computed.getPropertyValue('border-top-width'), 10)
                 + parseInt(computed.getPropertyValue('padding-top'), 10)
                 + field.scrollHeight
                 + parseInt(computed.getPropertyValue('padding-bottom'), 10)
                 + parseInt(computed.getPropertyValue('border-bottom-width'), 10);

    field.style.height = height + 'px';

};

document.addEventListener('input', function (event) {
    if (event.target.tagName.toLowerCase() !== 'textarea') return;
    autoExpand(event.target);
}, false);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52377216

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档