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

问题描述 投票:-1回答:1

我必须使用香草js和scss制作一个可重用的按钮组件,但是我还没有做。有人可以解释我该怎么做吗?我是新来的,所以我不知道在哪里寻找。

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

javascript html css sass web-component
1个回答
0
投票

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

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 );
© www.soinside.com 2019 - 2024. All rights reserved.