在尝试添加代码以自动展开文本框时,我得到了这个错误--来自以下代码:https://codepen.io/vsync/pen/frudD。我需要以不同的方式添加它吗?它当前位于vue组件文件中的脚本标记之间。
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)
发布于 2018-09-18 09:31:23
我使用了下面的代码,它工作得很好。
https://jsfiddle.net/cferdinandi/mqwwpL6u/
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);
https://stackoverflow.com/questions/52377216
复制相似问题