如何使用 vanilla js 和 sass 创建可重用的按钮组件?

How to create reusable button component with vanilla js and sass?

我必须用 vanilla js 和 scss 制作一个可重用的按钮组件,但我还没有完成。有人可以解释我该怎么做吗? 我是新手,所以不知道去哪里找。

更新:我必须使用 javascript 还是只能使用 HTML 和 SCSS/CSS?

有很多解决方案可以做到这一点。一个简单的解决方案是在 css 上创建样式并在不同的子类之间切换,然后,创建一个方法 o 函数 return 这个具有值的组件。

var cusButton =  (i_params )  => {
var curButton = document.createElement ('INPUT'), buttonContainer;
curButton.classList.add  (i_params.classname);
curButton.type = 'button';
curButton.value = i_params.valueButton;
//the classname has the properties that you have to create before...
buttonContainer = document.getElementById
(i_params.idButContainer);
buttonContainer.appenChild  (curButton);

}

//Then, create one object for each button and call this function to populate the DOM with the new buttons:

var propButton ={ classname : 'created-class', valueButton : 'Click here to sens', idButContainer : 'id-name-node'};

cusButton  (propButton );